Skip to content

Commit

Permalink
Modified test to check for correct instance definition order and elem…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
rahulreddy15 committed Oct 30, 2024
1 parent 5a71164 commit 8ee389b
Showing 1 changed file with 39 additions and 25 deletions.
64 changes: 39 additions & 25 deletions src/metrics/instance_definitions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,66 @@ import (

func Test_generateInstanceDefinitions(t *testing.T) {
tests := []struct {
name string
version string
expectedLength int
name string
version string
expectedQueries []*QueryDefinition
errorExpected bool
}{
{
name: "PostgreSQL 9.0",
version: "9.0.0",
expectedLength: 1,
name: "PostgreSQL 9.0",
version: "9.0.0",
expectedQueries: []*QueryDefinition{instanceDefinitionBase},
errorExpected: false,
},
{
name: "PostgreSQL 9.1",
version: "9.1.0",
expectedLength: 2,
name: "PostgreSQL 9.1",
version: "9.1.0",
expectedQueries: []*QueryDefinition{instanceDefinitionBase, instanceDefinition91},
errorExpected: false,
},
{
name: "PostgreSQL 9.2",
version: "9.2.0",
expectedLength: 3,
name: "PostgreSQL 9.2",
version: "9.2.0",
expectedQueries: []*QueryDefinition{instanceDefinitionBase, instanceDefinition91, instanceDefinition92},
errorExpected: false,
},
{
name: "PostgreSQL 10.2",
version: "10.2.0",
expectedLength: 3,
name: "PostgreSQL 10.2",
version: "10.2.0",
expectedQueries: []*QueryDefinition{instanceDefinitionBase, instanceDefinition91, instanceDefinition92},
errorExpected: false,
},
{
name: "PostgreSQL 16.4",
version: "16.4.2",
expectedLength: 3,
name: "PostgreSQL 16.4",
version: "16.4.2",
expectedQueries: []*QueryDefinition{instanceDefinitionBase, instanceDefinition91, instanceDefinition92},
errorExpected: false,
},
{
name: "PostgreSQL 17.0",
version: "17.0.0",
expectedLength: 3,
name: "PostgreSQL 17.0",
version: "17.0.0",
expectedQueries: []*QueryDefinition{instanceDefinitionBase170, instanceDefinition170, instanceDefinitionInputOutput170},
errorExpected: false,
},
{
name: "PostgreSQL 17.5",
version: "17.5.0",
expectedLength: 3,
name: "PostgreSQL 17.5 out of order",
version: "17.5.0",
expectedQueries: []*QueryDefinition{instanceDefinition170, instanceDefinitionInputOutput170, instanceDefinitionBase},
errorExpected: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
version := semver.MustParse(tt.version)
queryDefinitions := generateInstanceDefinitions(&version)
assert.Equal(t, tt.expectedLength, len(queryDefinitions))
assert.Equal(t, len(tt.expectedQueries), len(queryDefinitions))

if tt.errorExpected {
assert.False(t, assert.ObjectsAreEqual(tt.expectedQueries, queryDefinitions))
} else {
assert.ElementsMatch(t, tt.expectedQueries, queryDefinitions)
}
})
}
}

0 comments on commit 8ee389b

Please sign in to comment.