diff --git a/pkg/apis/testharness/v1beta1/commands.go b/pkg/apis/testharness/v1beta1/commands.go index b7e32334..b96dea50 100644 --- a/pkg/apis/testharness/v1beta1/commands.go +++ b/pkg/apis/testharness/v1beta1/commands.go @@ -29,11 +29,6 @@ func (c *CommandOutput) ValidateCommandOutput(stdoutOutput, stderrOutput strings func (e *ExpectedOutput) validateOutput(outputType string, actualValue string) error { expectedValue := e.ExpectedValue switch e.MatchType { - case MatchEquals: - if actualValue != expectedValue { - return fmt.Errorf("expected exact %s: %s, got: %s", outputType, expectedValue, actualValue) - } - case MatchContains: if !strings.Contains(actualValue, expectedValue) { return fmt.Errorf("expected %s to contain: %s, but it did not", outputType, expectedValue) @@ -44,8 +39,10 @@ func (e *ExpectedOutput) validateOutput(outputType string, actualValue string) e return fmt.Errorf("%s did not match wildcard pattern: %s", outputType, expectedValue) } - default: - return fmt.Errorf("invalid %s match type: %s", outputType, e.MatchType) + default: // MatchEquals + if actualValue != expectedValue { + return fmt.Errorf("expected exact %s: %s, got: %s", outputType, expectedValue, actualValue) + } } return nil diff --git a/pkg/apis/testharness/v1beta1/commands_test.go b/pkg/apis/testharness/v1beta1/commands_test.go index 08d21267..1c3d1dd9 100644 --- a/pkg/apis/testharness/v1beta1/commands_test.go +++ b/pkg/apis/testharness/v1beta1/commands_test.go @@ -270,6 +270,21 @@ func TestValidateCommandOutput(t *testing.T) { }(), wantErr: true, }, + { + name: "Empty Expected Output", + cmdOutput: CommandOutput{ + Stderr: &ExpectedOutput{ + MatchType: MatchContains, + ExpectedValue: "", + }, + }, + stderrOutput: func() strings.Builder { + b := strings.Builder{} + b.WriteString("Empty Expected Output") + return b + }(), + wantErr: false, + }, } for _, tt := range tests {