diff --git a/controllers/clickhousegrant_controller.go b/controllers/clickhousegrant_controller.go index a0ce655a..17a191dd 100644 --- a/controllers/clickhousegrant_controller.go +++ b/controllers/clickhousegrant_controller.go @@ -5,9 +5,9 @@ package controllers import ( "context" "fmt" + "net/http" "slices" "strconv" - "strings" "github.com/aiven/aiven-go-client/v2" avngen "github.com/aiven/go-client-codegen" diff --git a/tests/cassandra_test.go b/tests/cassandra_test.go index 7a992d9f..c3675e14 100644 --- a/tests/cassandra_test.go +++ b/tests/cassandra_test.go @@ -56,7 +56,7 @@ func TestCassandra(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/clickhouse_test.go b/tests/clickhouse_test.go index 63e96300..9825d246 100644 --- a/tests/clickhouse_test.go +++ b/tests/clickhouse_test.go @@ -65,7 +65,7 @@ func TestClickhouse(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/clickhousegrant_test.go b/tests/clickhousegrant_test.go index 853b050e..974a2453 100644 --- a/tests/clickhousegrant_test.go +++ b/tests/clickhousegrant_test.go @@ -133,7 +133,7 @@ func TestClickhouseGrant(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/clickhouseuser_test.go b/tests/clickhouseuser_test.go index d8c9c9c9..4b492a5d 100644 --- a/tests/clickhouseuser_test.go +++ b/tests/clickhouseuser_test.go @@ -33,7 +33,7 @@ func TestClickhouseUser(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/connectionpool_test.go b/tests/connectionpool_test.go index 07bfbedc..7f3079be 100644 --- a/tests/connectionpool_test.go +++ b/tests/connectionpool_test.go @@ -33,7 +33,7 @@ func TestConnectionPool(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/database_test.go b/tests/database_test.go index 434c4721..1ab9f477 100644 --- a/tests/database_test.go +++ b/tests/database_test.go @@ -55,7 +55,7 @@ func TestDatabase(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/generic_service_handler_test.go b/tests/generic_service_handler_test.go index 7ae8307d..3b70a9e4 100644 --- a/tests/generic_service_handler_test.go +++ b/tests/generic_service_handler_test.go @@ -70,7 +70,7 @@ func TestCreateUpdateService(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest @@ -130,7 +130,7 @@ func TestErrorCondition(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/grafana_test.go b/tests/grafana_test.go index ae30124d..6d65262c 100644 --- a/tests/grafana_test.go +++ b/tests/grafana_test.go @@ -55,7 +55,7 @@ func TestGrafana(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/kafka_test.go b/tests/kafka_test.go index 981fcf65..873d5a6c 100644 --- a/tests/kafka_test.go +++ b/tests/kafka_test.go @@ -57,7 +57,7 @@ func TestKafka(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/kafka_with_projectvpc_ref_test.go b/tests/kafka_with_projectvpc_ref_test.go index 93bfc520..94b5c1b5 100644 --- a/tests/kafka_with_projectvpc_ref_test.go +++ b/tests/kafka_with_projectvpc_ref_test.go @@ -60,7 +60,7 @@ func TestKafkaWithProjectVPCRef(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/kafkaacl_test.go b/tests/kafkaacl_test.go index 36d7dde2..35b9984e 100644 --- a/tests/kafkaacl_test.go +++ b/tests/kafkaacl_test.go @@ -77,7 +77,7 @@ func TestKafkaACL(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/kafkaconnect_test.go b/tests/kafkaconnect_test.go index cc751449..07ca29d9 100644 --- a/tests/kafkaconnect_test.go +++ b/tests/kafkaconnect_test.go @@ -55,7 +55,7 @@ func TestKafkaConnect(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/kafkaschema_test.go b/tests/kafkaschema_test.go index 3ce2d69d..7187b9a0 100644 --- a/tests/kafkaschema_test.go +++ b/tests/kafkaschema_test.go @@ -76,7 +76,7 @@ func TestKafkaSchema(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/kafkatopic_test.go b/tests/kafkatopic_test.go index ab24edb1..2014c6d7 100644 --- a/tests/kafkatopic_test.go +++ b/tests/kafkatopic_test.go @@ -85,7 +85,7 @@ func TestKafkaTopic(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/kafkschemaregistryaacl_test.go b/tests/kafkschemaregistryaacl_test.go index c39326d0..67c8ec2e 100644 --- a/tests/kafkschemaregistryaacl_test.go +++ b/tests/kafkschemaregistryaacl_test.go @@ -79,7 +79,7 @@ func TestKafkaSchemaRegistryACL(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/mysql_test.go b/tests/mysql_test.go index 28d90bdd..502aa671 100644 --- a/tests/mysql_test.go +++ b/tests/mysql_test.go @@ -55,7 +55,7 @@ func TestMySQL(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/opensearch_test.go b/tests/opensearch_test.go index 761714a8..994d9025 100644 --- a/tests/opensearch_test.go +++ b/tests/opensearch_test.go @@ -60,7 +60,7 @@ func TestOpenSearch(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/postgresql_test.go b/tests/postgresql_test.go index 48123889..47a103bc 100644 --- a/tests/postgresql_test.go +++ b/tests/postgresql_test.go @@ -77,7 +77,7 @@ func TestPgReadReplica(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest @@ -195,7 +195,7 @@ func TestPgCustomPrefix(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest @@ -287,7 +287,7 @@ func TestPgUpgradeVersion(t *testing.T) { yaml := getPgUpgradeVersionYaml(cfg.Project, pgName, cfg.PrimaryCloudName, startingVersion) s := NewSession(ctx, k8sClient, cfg.Project) - defer s.Destroy() + defer s.Destroy(t) require.NoError(t, s.Apply(yaml)) diff --git a/tests/project_test.go b/tests/project_test.go index cbbf408e..178e5190 100644 --- a/tests/project_test.go +++ b/tests/project_test.go @@ -43,7 +43,7 @@ func TestProject(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/projectvpc_test.go b/tests/projectvpc_test.go index 28454b39..0b1d66c7 100644 --- a/tests/projectvpc_test.go +++ b/tests/projectvpc_test.go @@ -78,7 +78,7 @@ func TestProjectVPCID(t *testing.T) { vpcSession := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer vpcSession.Destroy() + defer vpcSession.Destroy(t) // WHEN // Applies given manifest @@ -115,7 +115,7 @@ func TestProjectVPCID(t *testing.T) { kafkaSession := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer kafkaSession.Destroy() + defer kafkaSession.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/redis_test.go b/tests/redis_test.go index 4429c796..939526ba 100644 --- a/tests/redis_test.go +++ b/tests/redis_test.go @@ -52,7 +52,7 @@ func TestRedis(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/service_opts_test.go b/tests/service_opts_test.go index 255322f1..98be9992 100644 --- a/tests/service_opts_test.go +++ b/tests/service_opts_test.go @@ -49,7 +49,7 @@ func TestServiceTechnicalEmails(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest @@ -121,7 +121,7 @@ func runTest(t *testing.T, scenario TestScenario) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/serviceintegration_test.go b/tests/serviceintegration_test.go index 94258d04..ecae764b 100644 --- a/tests/serviceintegration_test.go +++ b/tests/serviceintegration_test.go @@ -35,7 +35,7 @@ func TestServiceIntegrationClickhousePostgreSQL(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest @@ -107,7 +107,7 @@ func TestServiceIntegrationKafkaLogs(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest @@ -176,7 +176,7 @@ func TestServiceIntegrationKafkaConnect(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest @@ -254,7 +254,7 @@ func TestServiceIntegrationDatadog(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/serviceintegrationendpoint_test.go b/tests/serviceintegrationendpoint_test.go index e54b0847..f4650351 100644 --- a/tests/serviceintegrationendpoint_test.go +++ b/tests/serviceintegrationendpoint_test.go @@ -27,7 +27,7 @@ func TestServiceIntegrationEndpointExternalPostgres(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest @@ -70,7 +70,7 @@ func TestServiceIntegrationEndpoint(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/serviceuser_test.go b/tests/serviceuser_test.go index 303d073e..82afcc06 100644 --- a/tests/serviceuser_test.go +++ b/tests/serviceuser_test.go @@ -67,7 +67,7 @@ func TestServiceUserKafka(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest @@ -189,7 +189,7 @@ func TestServiceUserPg(t *testing.T) { s := NewSession(ctx, k8sClient, cfg.Project) // Cleans test afterward - defer s.Destroy() + defer s.Destroy(t) // WHEN // Applies given manifest diff --git a/tests/session.go b/tests/session.go index 491ed3b2..9ad894a5 100644 --- a/tests/session.go +++ b/tests/session.go @@ -12,10 +12,12 @@ import ( "runtime/debug" "strings" "sync" + "testing" "time" "github.com/aiven/aiven-go-client/v2" avngen "github.com/aiven/go-client-codegen" + "github.com/stretchr/testify/assert" "golang.org/x/sync/errgroup" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -42,7 +44,7 @@ type Session interface { Apply(src string) error GetRunning(obj client.Object, keys ...string) error GetSecret(keys ...string) (*corev1.Secret, error) - Destroy() + Destroy(t *testing.T) Delete(o client.Object, exists func() error) error } @@ -153,9 +155,9 @@ func (s *session) GetSecret(keys ...string) (*corev1.Secret, error) { // Destroy deletes all applied resources. // Tolerant to "not found" error, // because resource may have been deleted manually -func (s *session) Destroy() { +func (s *session) Destroy(t *testing.T) { if err := recover(); err != nil { - log.Printf("panicked, deleting resources: %s", err) + t.Fatalf("panicked, deleting resources: %s", err) } var wg sync.WaitGroup @@ -166,7 +168,7 @@ func (s *session) Destroy() { defer s.recover() err := s.delete(s.objs[n]) if !(err == nil || isNotFound(err)) { - log.Printf("failed to delete %q: %s", n, err) + assert.Error(t, err, "failed to delete %q", n) } }(n) }