Skip to content

Commit

Permalink
adding cli test command_test to the make test-update
Browse files Browse the repository at this point in the history
  • Loading branch information
shireenf-ibm committed Nov 19, 2023
1 parent f20ee2b commit 8757a78
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ test:

test-update: # overrides/ generates tests' expected output files for relevant tests
@echo -- $@ --
go test ./pkg/netpol/connlist/ ./pkg/netpol/diff/ --args --update
go test ./pkg/netpol/connlist/ ./pkg/netpol/diff/ ./pkg/cli --args --update
10 changes: 10 additions & 0 deletions pkg/cli/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ func testInfo(testName string) string {
return fmt.Sprintf("test: %q", testName)
}

// removes the output file generated for commands which run with `-f` flag
func removeOutFile(t *testing.T, outputFile, testInfo string) {
if outputFile != "" {
err := os.Remove(outputFile)
require.Nil(t, err, testInfo)
}
}

// TestCommandsFailExecute - tests executing failure for illegal commands or commands with invalid args or with wrong input values
func TestCommandsFailExecute(t *testing.T) {
tests := []struct {
Expand Down Expand Up @@ -259,6 +267,7 @@ func TestListCommandOutput(t *testing.T) {
require.Nil(t, err, "test: %q", testName)
testutils.CheckActualVsExpectedOutputMatch(t, tt.dirName, expectedOutputFileName, actualOut, testInfo(testName), tt.outputFile,
currentDirDepth, specialOutFileFlag)
removeOutFile(t, tt.outputFile, testInfo(testName))
})
}
}
Expand Down Expand Up @@ -310,6 +319,7 @@ func TestDiffCommandOutput(t *testing.T) {
expectedOutputFileName := getDiffCmdExpectedOutputFile(tt.dir1, tt.format)
testutils.CheckActualVsExpectedOutputMatch(t, tt.dir2, expectedOutputFileName, actualOut, testInfo(testName), tt.outputFile,
currentDirDepth, false)
removeOutFile(t, tt.outputFile, testInfo(testName))
})
}
}
Expand Down
1 change: 0 additions & 1 deletion pkg/internal/testutils/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ func compareFileContentsVsExpectedOutput(t *testing.T, testInfo, outFile, expect
require.Nil(t, err, testInfo)
require.Equal(t, cleanStr(expectedOutput), cleanStr(string(fileContent)),
"output mismatch for test %q, actual output file %q vs expected output file: %q", testInfo, outFile, expectedOutputFile)
os.Remove(outFile)
}

func cleanStr(str string) string {
Expand Down

0 comments on commit 8757a78

Please sign in to comment.