Skip to content

Commit

Permalink
Final test passes
Browse files Browse the repository at this point in the history
  • Loading branch information
malcolmholmes committed Mar 1, 2024
1 parent a56f526 commit 54419a6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
7 changes: 5 additions & 2 deletions integration/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ func TestDatasources(t *testing.T) {
ExpectedOutput: "Datasource.datasource-broken added\n",
},
{
Command: "get -o json Datasource.datasource-broken",
ExpectedOutputFile: "datasource-broken-returned.json",
Command: "get -o json Datasource.datasource-broken",
ExpectedOutputFiles: []string{
"datasource-broken-returned.json",
"datasource-broken-returned2.json",
},
},
},
})
Expand Down
16 changes: 16 additions & 0 deletions integration/testdata/datasources/datasource-broken-returned2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"apiVersion": "grizzly.grafana.com/v1alpha1",
"kind": "Datasource",
"metadata": {
"name": "datasource-broken"
},
"spec": {
"access": "proxy",
"jsonData": {},
"name": "InfluxDB",
"orgId": 1,
"type": "influxdb",
"typeLogoUrl": "/grafana/public/app/plugins/datasource/influxdb/img/influxdb_logo.svg",
"uid": "datasource-broken"
}
}
11 changes: 11 additions & 0 deletions integration/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Command struct {
ExpectedLogsContain string
ExpectedOutput string
ExpectedOutputFile string
ExpectedOutputFiles []string
ExpectedOutputContains string
}
type GrizzlyTest struct {
Expand Down Expand Up @@ -61,6 +62,16 @@ func runTest(t *testing.T, test GrizzlyTest) {
require.NoError(t, err)
command.ExpectedOutput = string(bytes)
}
if command.ExpectedOutputFiles != nil {
var expectedOutputs []string
for _, expectedOutputFile := range command.ExpectedOutputFiles {
bytes, err := os.ReadFile(filepath.Join(test.TestDir, expectedOutputFile))
require.NoError(t, err)
expectedOutputs = append(expectedOutputs, strings.TrimSpace(string(bytes)))
}
require.Contains(t, expectedOutputs, strings.TrimSpace(stdout))

}
if command.ExpectedOutput != "" {
require.Equal(t, strings.TrimSpace(command.ExpectedOutput), strings.TrimSpace(stdout))
}
Expand Down

0 comments on commit 54419a6

Please sign in to comment.