Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Bringing in features from #325
  • Loading branch information
julienduchesne committed Feb 2, 2024
1 parent a4f4086 commit 830de78
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
6 changes: 3 additions & 3 deletions integration/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ func TestContexts(t *testing.T) {
TestDir: "testdata/contexts",
Commands: []Command{
{
Command: "config get-contexts",
ExpectedCode: 0,
ExpectedOutput: "get-contexts.txt",
Command: "config get-contexts",
ExpectedCode: 0,
ExpectedOutputFile: "get-contexts.txt",
},
},
})
Expand Down
6 changes: 3 additions & 3 deletions integration/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ func TestDashboard(t *testing.T) {
RunOnContexts: allContexts,
Commands: []Command{
{
Command: "get Dashboard.ReciqtgGk",
ExpectedCode: 0,
ExpectedOutput: "ReciqtgGk.json",
Command: "get Dashboard.ReciqtgGk",
ExpectedCode: 0,
ExpectedOutputFile: "ReciqtgGk.json",
},
},
})
Expand Down
11 changes: 8 additions & 3 deletions integration/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Command struct {
ExpectedCode int
ExpectedError error
ExpectedOutput string
ExpectedOutputFile string
ExpectedOutputContains string
}
type GrizzlyTest struct {
Expand Down Expand Up @@ -46,10 +47,14 @@ func runTest(t *testing.T, test GrizzlyTest) {
require.Error(t, err, command.ExpectedError)
}
require.Equal(t, command.ExpectedCode, exitCode, "Exited with %d (%d expected).\nOutput: %s\nstderr: %s", exitCode, command.ExpectedCode, stdout, stderr)
if command.ExpectedOutput != "" {
data, err := os.ReadFile(filepath.Join(test.TestDir, command.ExpectedOutput))
// Check stdout
if command.ExpectedOutputFile != "" {
bytes, err := os.ReadFile(filepath.Join(test.TestDir, command.ExpectedOutputFile))
require.NoError(t, err)
require.Equal(t, string(data), stdout)
command.ExpectedOutput = string(bytes)
}
if command.ExpectedOutput != "" {
require.Equal(t, command.ExpectedOutput, stdout)
}
if command.ExpectedOutputContains != "" {
require.Contains(t, stdout, command.ExpectedOutputContains)
Expand Down

0 comments on commit 830de78

Please sign in to comment.