Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
fixed changes
Browse files Browse the repository at this point in the history
Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
  • Loading branch information
shubham-cmyk committed Sep 15, 2023
1 parent b5755a8 commit 4cb3570
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
11 changes: 4 additions & 7 deletions pkg/apis/testharness/v1beta1/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
15 changes: 15 additions & 0 deletions pkg/apis/testharness/v1beta1/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4cb3570

Please sign in to comment.