From 8ee389b46ee52984141bcace9bfd6452c9b425e6 Mon Sep 17 00:00:00 2001 From: rahul Date: Wed, 30 Oct 2024 15:47:18 +0530 Subject: [PATCH] Modified test to check for correct instance definition order and elements --- src/metrics/instance_definitions_test.go | 64 +++++++++++++++--------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/src/metrics/instance_definitions_test.go b/src/metrics/instance_definitions_test.go index 6e88f27..f4d6b8f 100644 --- a/src/metrics/instance_definitions_test.go +++ b/src/metrics/instance_definitions_test.go @@ -9,44 +9,52 @@ 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, }, } @@ -54,7 +62,13 @@ func Test_generateInstanceDefinitions(t *testing.T) { 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) + } }) } }