Skip to content

Commit

Permalink
PMM-5086-12634 Fix PG test suite.
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriCtvrtka committed Dec 4, 2024
1 parent 0c196b9 commit 2935856
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions managed/services/agents/postgresql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func (s *PostgresExporterConfigTestSuite) SetupTest() {
}

func (s *PostgresExporterConfigTestSuite) TestConfig() {
s.exporter.ExporterOptions = &models.ExporterOptions{}
s.exporter.AzureOptions = &models.AzureOptions{}
s.exporter.PostgreSQLOptions = &models.PostgreSQLOptions{}

actual, err := postgresExporterConfig(s.node, s.postgresql, s.exporter, redactSecrets, s.pmmAgentVersion)
s.NoError(err, "Failed to create exporter config")

Expand All @@ -92,6 +96,10 @@ func (s *PostgresExporterConfigTestSuite) TestDatabaseName() {
s.postgresql.DatabaseName = "db1"
s.expected.Env[0] = "DATA_SOURCE_NAME=postgres://username:s3cur3%20p%[email protected]:5432/db1?connect_timeout=1&sslmode=disable"

s.exporter.ExporterOptions = &models.ExporterOptions{}
s.exporter.AzureOptions = &models.AzureOptions{}
s.exporter.PostgreSQLOptions = &models.PostgreSQLOptions{}

actual, err := postgresExporterConfig(s.node, s.postgresql, s.exporter, redactSecrets, s.pmmAgentVersion)
s.NoError(err, "Failed to create exporter config")

Expand All @@ -102,6 +110,10 @@ func (s *PostgresExporterConfigTestSuite) TestDatabaseName() {
s.postgresql.DatabaseName = ""

s.Require().PanicsWithValue("database name not set", func() {
s.exporter.ExporterOptions = &models.ExporterOptions{}
s.exporter.AzureOptions = &models.AzureOptions{}
s.exporter.PostgreSQLOptions = &models.PostgreSQLOptions{}

_, err := postgresExporterConfig(s.node, s.postgresql, s.exporter, redactSecrets, s.pmmAgentVersion)
s.NoError(err, "Failed to create exporter config")
})
Expand All @@ -110,6 +122,9 @@ func (s *PostgresExporterConfigTestSuite) TestDatabaseName() {

func (s *PostgresExporterConfigTestSuite) TestEmptyPassword() {
s.exporter.Password = nil
s.exporter.ExporterOptions = &models.ExporterOptions{}
s.exporter.AzureOptions = &models.AzureOptions{}
s.exporter.PostgreSQLOptions = &models.PostgreSQLOptions{}

actual, err := postgresExporterConfig(s.node, s.postgresql, s.exporter, exposeSecrets, s.pmmAgentVersion)
s.NoError(err, "Failed to create exporter config")
Expand All @@ -119,6 +134,9 @@ func (s *PostgresExporterConfigTestSuite) TestEmptyPassword() {

func (s *PostgresExporterConfigTestSuite) TestEmptyUsername() {
s.exporter.Username = nil
s.exporter.ExporterOptions = &models.ExporterOptions{}
s.exporter.AzureOptions = &models.AzureOptions{}
s.exporter.PostgreSQLOptions = &models.PostgreSQLOptions{}

actual, err := postgresExporterConfig(s.node, s.postgresql, s.exporter, exposeSecrets, s.pmmAgentVersion)
s.NoError(err, "Failed to create exporter config")
Expand All @@ -129,6 +147,9 @@ func (s *PostgresExporterConfigTestSuite) TestEmptyUsername() {
func (s *PostgresExporterConfigTestSuite) TestEmptyUsernameAndPassword() {
s.exporter.Username = nil
s.exporter.Password = nil
s.exporter.ExporterOptions = &models.ExporterOptions{}
s.exporter.AzureOptions = &models.AzureOptions{}
s.exporter.PostgreSQLOptions = &models.PostgreSQLOptions{}

actual, err := postgresExporterConfig(s.node, s.postgresql, s.exporter, exposeSecrets, s.pmmAgentVersion)
s.NoError(err, "Failed to create exporter config")
Expand All @@ -142,6 +163,9 @@ func (s *PostgresExporterConfigTestSuite) TestSocket() {
s.postgresql.Address = nil
s.postgresql.Port = nil
s.postgresql.Socket = pointer.ToString("/var/run/postgres")
s.exporter.ExporterOptions = &models.ExporterOptions{}
s.exporter.AzureOptions = &models.AzureOptions{}
s.exporter.PostgreSQLOptions = &models.PostgreSQLOptions{}

actual, err := postgresExporterConfig(s.node, s.postgresql, s.exporter, exposeSecrets, s.pmmAgentVersion)
s.NoError(err, "Failed to create exporter config")
Expand All @@ -157,6 +181,8 @@ func (s *PostgresExporterConfigTestSuite) TestDisabledCollectors() {
s.exporter.ExporterOptions = &models.ExporterOptions{
DisabledCollectors: []string{"custom_query.hr", "custom_query.hr.directory", "locks"},
}
s.exporter.AzureOptions = &models.AzureOptions{}
s.exporter.PostgreSQLOptions = &models.PostgreSQLOptions{}

actual, err := postgresExporterConfig(s.node, s.postgresql, s.exporter, exposeSecrets, s.pmmAgentVersion)
s.NoError(err, "Failed to create exporter config")
Expand Down Expand Up @@ -536,11 +562,5 @@ func (s *PostgresExporterConfigTestSuite) TestSSLSni() {
}

func TestPostgresExporterConfigTestSuite(t *testing.T) {
suite.Run(t, &PostgresExporterConfigTestSuite{
exporter: &models.Agent{
ExporterOptions: &models.ExporterOptions{},
AzureOptions: &models.AzureOptions{},
PostgreSQLOptions: &models.PostgreSQLOptions{},
},
})
suite.Run(t, &PostgresExporterConfigTestSuite{})
}

0 comments on commit 2935856

Please sign in to comment.