diff --git a/go.mod b/go.mod index 20b1fb41a..cb03016f2 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/ghodss/yaml v1.0.0 github.com/go-logr/logr v1.4.1 github.com/google/go-cmp v0.6.0 + github.com/kelseyhightower/envconfig v1.4.0 github.com/liip/sheriff v0.11.1 github.com/otiai10/copy v1.14.0 github.com/stoewer/go-strcase v1.3.0 @@ -52,7 +53,6 @@ require ( github.com/imdario/mergo v0.3.12 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/kelseyhightower/envconfig v1.4.0 // indirect github.com/mailru/easyjson v0.7.6 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect diff --git a/tests/cassandra_test.go b/tests/cassandra_test.go index 6e7b6b80d..4d7bfdf6b 100644 --- a/tests/cassandra_test.go +++ b/tests/cassandra_test.go @@ -51,10 +51,10 @@ func TestCassandra(t *testing.T) { // GIVEN ctx := context.Background() name := randName("cassandra") - yml := getCassandraYaml(testProject, name, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getCassandraYaml(cfg.Project, name, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) - // Cleans test afterwards + // Cleans test afterward defer s.Destroy() // WHEN @@ -66,7 +66,7 @@ func TestCassandra(t *testing.T) { require.NoError(t, s.GetRunning(cs, name)) // THEN - csAvn, err := avnClient.Services.Get(ctx, testProject, name) + csAvn, err := avnClient.Services.Get(ctx, cfg.Project, name) require.NoError(t, err) assert.Equal(t, csAvn.Name, cs.GetName()) assert.Equal(t, "RUNNING", cs.Status.State) @@ -76,7 +76,7 @@ func TestCassandra(t *testing.T) { assert.Equal(t, "450Gib", cs.Spec.DiskSpace) assert.Equal(t, 460800, csAvn.DiskSpaceMB) assert.Equal(t, map[string]string{"env": "test", "instance": "foo"}, cs.Spec.Tags) - csResp, err := avnClient.ServiceTags.Get(ctx, testProject, name) + csResp, err := avnClient.ServiceTags.Get(ctx, cfg.Project, name) require.NoError(t, err) assert.Equal(t, csResp.Tags, cs.Spec.Tags) diff --git a/tests/clickhouse_test.go b/tests/clickhouse_test.go index ba2dfd1de..6c1637036 100644 --- a/tests/clickhouse_test.go +++ b/tests/clickhouse_test.go @@ -47,8 +47,8 @@ func TestClickhouse(t *testing.T) { // GIVEN ctx := context.Background() name := randName("clickhouse") - yml := getClickhouseYaml(testProject, name, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getClickhouseYaml(cfg.Project, name, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -62,7 +62,7 @@ func TestClickhouse(t *testing.T) { require.NoError(t, s.GetRunning(ch, name)) // THEN - chAvn, err := avnClient.Services.Get(ctx, testProject, name) + chAvn, err := avnClient.Services.Get(ctx, cfg.Project, name) require.NoError(t, err) assert.Equal(t, chAvn.Name, ch.GetName()) assert.Equal(t, "RUNNING", ch.Status.State) @@ -70,7 +70,7 @@ func TestClickhouse(t *testing.T) { assert.Equal(t, chAvn.Plan, ch.Spec.Plan) assert.Equal(t, chAvn.CloudName, ch.Spec.CloudName) assert.Equal(t, map[string]string{"env": "test", "instance": "foo"}, ch.Spec.Tags) - chResp, err := avnClient.ServiceTags.Get(ctx, testProject, name) + chResp, err := avnClient.ServiceTags.Get(ctx, cfg.Project, name) require.NoError(t, err) assert.Equal(t, chResp.Tags, ch.Spec.Tags) diff --git a/tests/clickhouseuser_test.go b/tests/clickhouseuser_test.go index c6803d4c4..93ad6f60e 100644 --- a/tests/clickhouseuser_test.go +++ b/tests/clickhouseuser_test.go @@ -58,8 +58,8 @@ func TestClickhouseUser(t *testing.T) { ctx := context.Background() chName := randName("clickhouse-user") userName := randName("clickhouse-user") - yml := getClickhouseUserYaml(testProject, chName, userName, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getClickhouseUserYaml(cfg.Project, chName, userName, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -73,7 +73,7 @@ func TestClickhouseUser(t *testing.T) { require.NoError(t, s.GetRunning(ch, chName)) // THEN - chAvn, err := avnClient.Services.Get(ctx, testProject, chName) + chAvn, err := avnClient.Services.Get(ctx, cfg.Project, chName) require.NoError(t, err) assert.Equal(t, chAvn.Name, ch.GetName()) assert.Equal(t, "RUNNING", ch.Status.State) @@ -84,7 +84,7 @@ func TestClickhouseUser(t *testing.T) { user := new(v1alpha1.ClickhouseUser) require.NoError(t, s.GetRunning(user, userName)) - userAvn, err := avnClient.ClickhouseUser.Get(ctx, testProject, chName, user.Status.UUID) + userAvn, err := avnClient.ClickhouseUser.Get(ctx, cfg.Project, chName, user.Status.UUID) require.NoError(t, err) assert.Equal(t, userName, user.GetName()) assert.Equal(t, userAvn.Name, user.GetName()) @@ -107,7 +107,7 @@ func TestClickhouseUser(t *testing.T) { // if service is deleted, user is destroyed in Aiven. No service — no user. No user — no user. // And we make sure that controller can delete user itself assert.NoError(t, s.Delete(user, func() error { - _, err = avnClient.ClickhouseUser.Get(ctx, testProject, chName, user.Status.UUID) + _, err = avnClient.ClickhouseUser.Get(ctx, cfg.Project, chName, user.Status.UUID) return err })) } diff --git a/tests/connectionpool_test.go b/tests/connectionpool_test.go index c269ed27f..19a42b654 100644 --- a/tests/connectionpool_test.go +++ b/tests/connectionpool_test.go @@ -84,8 +84,8 @@ func TestConnectionPool(t *testing.T) { dbName := randName("connection-pool") userName := randName("connection-pool") poolName := randName("connection-pool") - yml := getConnectionPoolYaml(testProject, pgName, dbName, userName, poolName, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getConnectionPoolYaml(cfg.Project, pgName, dbName, userName, poolName, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -109,7 +109,7 @@ func TestConnectionPool(t *testing.T) { // THEN // Validates PostgreSQL - pgAvn, err := avnClient.Services.Get(ctx, testProject, pgName) + pgAvn, err := avnClient.Services.Get(ctx, cfg.Project, pgName) require.NoError(t, err) assert.Equal(t, pgAvn.Name, pg.GetName()) assert.Equal(t, "RUNNING", pg.Status.State) @@ -118,20 +118,20 @@ func TestConnectionPool(t *testing.T) { assert.Equal(t, pgAvn.CloudName, pg.Spec.CloudName) // Validates Database - dbAvn, err := avnClient.Databases.Get(ctx, testProject, pgName, dbName) + dbAvn, err := avnClient.Databases.Get(ctx, cfg.Project, pgName, dbName) require.NoError(t, err) assert.Equal(t, dbName, db.GetName()) assert.Equal(t, dbAvn.DatabaseName, db.GetName()) // Validates ServiceUser - userAvn, err := avnClient.ServiceUsers.Get(ctx, testProject, pgName, userName) + userAvn, err := avnClient.ServiceUsers.Get(ctx, cfg.Project, pgName, userName) require.NoError(t, err) assert.Equal(t, userName, user.GetName()) assert.Equal(t, userName, userAvn.Username) assert.Equal(t, pgName, user.Spec.ServiceName) // Validates ConnectionPool - poolAvn, err := avnClient.ConnectionPools.Get(ctx, testProject, pgName, poolName) + poolAvn, err := avnClient.ConnectionPools.Get(ctx, cfg.Project, pgName, poolName) require.NoError(t, err) assert.Equal(t, pgName, pool.Spec.ServiceName) assert.Equal(t, poolName, pool.GetName()) @@ -177,7 +177,7 @@ func TestConnectionPool(t *testing.T) { // if service is deleted, pool is destroyed in Aiven. No service — no pool. No pool — no pool. // And we make sure that controller can delete db itself assert.NoError(t, s.Delete(pool, func() error { - _, err = avnClient.ConnectionPools.Get(ctx, testProject, pgName, poolName) + _, err = avnClient.ConnectionPools.Get(ctx, cfg.Project, pgName, poolName) return err })) } diff --git a/tests/database_test.go b/tests/database_test.go index a2db6e7a3..6e2c5c7c0 100644 --- a/tests/database_test.go +++ b/tests/database_test.go @@ -54,8 +54,8 @@ func TestDatabase(t *testing.T) { ctx := context.Background() pgName := randName("database") dbName := randName("database") - yml := getDatabaseYaml(testProject, pgName, dbName, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getDatabaseYaml(cfg.Project, pgName, dbName, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -73,7 +73,7 @@ func TestDatabase(t *testing.T) { // THEN // Validates PostgreSQL - pgAvn, err := avnClient.Services.Get(ctx, testProject, pgName) + pgAvn, err := avnClient.Services.Get(ctx, cfg.Project, pgName) require.NoError(t, err) assert.Equal(t, pgAvn.Name, pg.GetName()) assert.Equal(t, "RUNNING", pg.Status.State) @@ -82,7 +82,7 @@ func TestDatabase(t *testing.T) { assert.Equal(t, pgAvn.CloudName, pg.Spec.CloudName) // Validates Database - dbAvn, err := avnClient.Databases.Get(ctx, testProject, pgName, dbName) + dbAvn, err := avnClient.Databases.Get(ctx, cfg.Project, pgName, dbName) require.NoError(t, err) assert.Equal(t, dbName, db.GetName()) assert.Equal(t, dbAvn.DatabaseName, db.GetName()) @@ -96,7 +96,7 @@ func TestDatabase(t *testing.T) { // if service is deleted, db is destroyed in Aiven. No service — no db. No db — no db. // And we make sure that controller can delete db itself assert.NoError(t, s.Delete(db, func() error { - _, err = avnClient.Databases.Get(ctx, testProject, pgName, dbName) + _, err = avnClient.Databases.Get(ctx, cfg.Project, pgName, dbName) return err })) } diff --git a/tests/generic_service_handler_test.go b/tests/generic_service_handler_test.go index c096d8211..79a19e7d9 100644 --- a/tests/generic_service_handler_test.go +++ b/tests/generic_service_handler_test.go @@ -60,8 +60,8 @@ func TestCreateUpdateService(t *testing.T) { // GIVEN ctx := context.Background() pgName := randName("generic-handler") - ymlCreate := getCreateServiceYaml(testProject, pgName) - s := NewSession(k8sClient, avnClient, testProject) + ymlCreate := getCreateServiceYaml(cfg.Project, pgName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -76,20 +76,20 @@ func TestCreateUpdateService(t *testing.T) { // THEN // Validates tags - tagsCreatedAvn, err := avnClient.ServiceTags.Get(ctx, testProject, pgName) + tagsCreatedAvn, err := avnClient.ServiceTags.Get(ctx, cfg.Project, pgName) require.NoError(t, err) assert.Equal(t, map[string]string{"env": "prod", "instance": "master"}, pg.Spec.Tags) assert.Equal(t, tagsCreatedAvn.Tags, pg.Spec.Tags) // Updates tags - ymlUpdate := getUpdateServiceYaml(testProject, pgName) + ymlUpdate := getUpdateServiceYaml(cfg.Project, pgName) require.NoError(t, err) require.NoError(t, s.Apply(ymlUpdate)) pgUpdated := new(v1alpha1.PostgreSQL) require.NoError(t, s.GetRunning(pgUpdated, pgName)) - tagsUpdatedAvn, err := avnClient.ServiceTags.Get(ctx, testProject, pgName) + tagsUpdatedAvn, err := avnClient.ServiceTags.Get(ctx, cfg.Project, pgName) require.NoError(t, err) assert.Empty(t, tagsUpdatedAvn.Tags) // cleared tags } @@ -118,8 +118,8 @@ func TestErrorCondition(t *testing.T) { // GIVEN ctx := context.Background() pgName := randName("generic-handler") - yml := getErrorConditionYaml(testProject, pgName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getErrorConditionYaml(cfg.Project, pgName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() diff --git a/tests/grafana_test.go b/tests/grafana_test.go index cc6bc367a..897fc42f5 100644 --- a/tests/grafana_test.go +++ b/tests/grafana_test.go @@ -50,8 +50,8 @@ func TestGrafana(t *testing.T) { // GIVEN ctx := context.Background() name := randName("grafana") - yml := getGrafanaYaml(testProject, name, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getGrafanaYaml(cfg.Project, name, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -65,7 +65,7 @@ func TestGrafana(t *testing.T) { require.NoError(t, s.GetRunning(grafana, name)) // THEN - grafanaAvn, err := avnClient.Services.Get(ctx, testProject, name) + grafanaAvn, err := avnClient.Services.Get(ctx, cfg.Project, name) require.NoError(t, err) assert.Equal(t, grafanaAvn.Name, grafana.GetName()) assert.Equal(t, "RUNNING", grafana.Status.State) @@ -73,7 +73,7 @@ func TestGrafana(t *testing.T) { assert.Equal(t, grafanaAvn.Plan, grafana.Spec.Plan) assert.Equal(t, grafanaAvn.CloudName, grafana.Spec.CloudName) assert.Equal(t, map[string]string{"env": "test", "instance": "foo"}, grafana.Spec.Tags) - grafanaResp, err := avnClient.ServiceTags.Get(ctx, testProject, name) + grafanaResp, err := avnClient.ServiceTags.Get(ctx, cfg.Project, name) require.NoError(t, err) assert.Equal(t, grafanaResp.Tags, grafana.Spec.Tags) diff --git a/tests/kafka_test.go b/tests/kafka_test.go index dab097ccc..0bf76bc36 100644 --- a/tests/kafka_test.go +++ b/tests/kafka_test.go @@ -52,8 +52,8 @@ func TestKafka(t *testing.T) { // GIVEN ctx := context.Background() name := randName("kafka") - yml := getKafkaYaml(testProject, name, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getKafkaYaml(cfg.Project, name, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -67,7 +67,7 @@ func TestKafka(t *testing.T) { require.NoError(t, s.GetRunning(ks, name)) // THEN - ksAvn, err := avnClient.Services.Get(ctx, testProject, name) + ksAvn, err := avnClient.Services.Get(ctx, cfg.Project, name) require.NoError(t, err) assert.Equal(t, ksAvn.Name, ks.GetName()) assert.Equal(t, "RUNNING", ks.Status.State) @@ -77,7 +77,7 @@ func TestKafka(t *testing.T) { assert.Equal(t, "600Gib", ks.Spec.DiskSpace) assert.Equal(t, 614400, ksAvn.DiskSpaceMB) assert.Equal(t, map[string]string{"env": "test", "instance": "foo"}, ks.Spec.Tags) - ksResp, err := avnClient.ServiceTags.Get(ctx, testProject, name) + ksResp, err := avnClient.ServiceTags.Get(ctx, cfg.Project, name) require.NoError(t, err) assert.Equal(t, ksResp.Tags, ks.Spec.Tags) diff --git a/tests/kafka_with_projectvpc_ref_test.go b/tests/kafka_with_projectvpc_ref_test.go index 3f17d9f7f..0fd9a8c50 100644 --- a/tests/kafka_with_projectvpc_ref_test.go +++ b/tests/kafka_with_projectvpc_ref_test.go @@ -55,8 +55,8 @@ func TestKafkaWithProjectVPCRef(t *testing.T) { ctx := context.Background() vpcName := randName("kafka-vpc") kafkaName := randName("kafka-vpc") - yml := getKafkaWithProjectVPCRefYaml(testProject, vpcName, kafkaName, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getKafkaWithProjectVPCRefYaml(cfg.Project, vpcName, kafkaName, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -73,7 +73,7 @@ func TestKafkaWithProjectVPCRef(t *testing.T) { require.NoError(t, s.GetRunning(vpc, vpcName)) // THEN - kafkaAvn, err := avnClient.Services.Get(ctx, testProject, kafkaName) + kafkaAvn, err := avnClient.Services.Get(ctx, cfg.Project, kafkaName) require.NoError(t, err) assert.Equal(t, kafkaAvn.Name, kafka.GetName()) assert.Equal(t, "RUNNING", kafka.Status.State) @@ -86,7 +86,7 @@ func TestKafkaWithProjectVPCRef(t *testing.T) { assert.Equal(t, vpcName, kafka.Spec.ProjectVPCRef.Name) assert.Equal(t, anyPointer(vpc.Status.ID), kafkaAvn.ProjectVPCID) - vpcAvn, err := avnClient.VPCs.Get(ctx, testProject, vpc.Status.ID) + vpcAvn, err := avnClient.VPCs.Get(ctx, cfg.Project, vpc.Status.ID) require.NoError(t, err) assert.Equal(t, "ACTIVE", vpcAvn.State) assert.Equal(t, vpcAvn.State, vpc.Status.State) diff --git a/tests/kafkaacl_test.go b/tests/kafkaacl_test.go index 299528b64..d18c9d38c 100644 --- a/tests/kafkaacl_test.go +++ b/tests/kafkaacl_test.go @@ -72,8 +72,8 @@ func TestKafkaACL(t *testing.T) { kafkaName := randName("kafka-acl") topicName := randName("kafka-acl") aclName := randName("kafka-acl") - yml := getKafkaACLYaml(testProject, kafkaName, topicName, aclName, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getKafkaACLYaml(cfg.Project, kafkaName, topicName, aclName, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -94,7 +94,7 @@ func TestKafkaACL(t *testing.T) { // THEN // Kafka - kafkaAvn, err := avnClient.Services.Get(ctx, testProject, kafkaName) + kafkaAvn, err := avnClient.Services.Get(ctx, cfg.Project, kafkaName) require.NoError(t, err) assert.Equal(t, kafkaAvn.Name, kafka.GetName()) assert.Equal(t, "RUNNING", kafka.Status.State) @@ -103,7 +103,7 @@ func TestKafkaACL(t *testing.T) { assert.Equal(t, kafkaAvn.CloudName, kafka.Spec.CloudName) // KafkaTopic - topicAvn, err := avnClient.KafkaTopics.Get(ctx, testProject, kafkaName, topic.GetTopicName()) + topicAvn, err := avnClient.KafkaTopics.Get(ctx, cfg.Project, kafkaName, topic.GetTopicName()) require.NoError(t, err) assert.Equal(t, topicName, topic.GetName()) assert.Equal(t, topicName, topic.GetTopicName()) @@ -113,7 +113,7 @@ func TestKafkaACL(t *testing.T) { assert.Len(t, topicAvn.Partitions, topic.Spec.Partitions) // KafkaACL - aclAvn, err := avnClient.KafkaACLs.Get(ctx, testProject, kafkaName, acl.Status.ID) + aclAvn, err := avnClient.KafkaACLs.Get(ctx, cfg.Project, kafkaName, acl.Status.ID) require.NoError(t, err) assert.True(t, meta.IsStatusConditionTrue(acl.Status.Conditions, "Running")) assert.Equal(t, "admin", acl.Spec.Permission) @@ -136,14 +136,14 @@ func TestKafkaACL(t *testing.T) { assert.NotEqual(t, aclWrite.Status.ID, acl.Status.ID) // Permission has changed on Aiven side too - aclWriteAvn, err := avnClient.KafkaACLs.Get(ctx, testProject, kafkaName, aclWrite.Status.ID) + aclWriteAvn, err := avnClient.KafkaACLs.Get(ctx, cfg.Project, kafkaName, aclWrite.Status.ID) require.NoError(t, err) assert.Equal(t, "write", aclWrite.Spec.Permission) assert.Equal(t, aclWriteAvn.Permission, aclWrite.Spec.Permission) // Validate delete by new ID assert.NoError(t, s.Delete(aclWrite, func() error { - _, err = avnClient.KafkaACLs.Get(ctx, testProject, kafkaName, aclWrite.Status.ID) + _, err = avnClient.KafkaACLs.Get(ctx, cfg.Project, kafkaName, aclWrite.Status.ID) return err })) } diff --git a/tests/kafkaconnect_test.go b/tests/kafkaconnect_test.go index 32978b36c..56badb4bf 100644 --- a/tests/kafkaconnect_test.go +++ b/tests/kafkaconnect_test.go @@ -50,8 +50,8 @@ func TestKafkaConnect(t *testing.T) { // GIVEN ctx := context.Background() name := randName("kafka-connect") - yml := getKafkaConnectYaml(testProject, name, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getKafkaConnectYaml(cfg.Project, name, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -65,7 +65,7 @@ func TestKafkaConnect(t *testing.T) { require.NoError(t, s.GetRunning(kc, name)) // THEN - kcAvn, err := avnClient.Services.Get(ctx, testProject, name) + kcAvn, err := avnClient.Services.Get(ctx, cfg.Project, name) require.NoError(t, err) assert.Equal(t, kcAvn.Name, kc.GetName()) assert.Equal(t, "RUNNING", kc.Status.State) diff --git a/tests/kafkaschema_test.go b/tests/kafkaschema_test.go index 8d4e60a04..628d573f3 100644 --- a/tests/kafkaschema_test.go +++ b/tests/kafkaschema_test.go @@ -71,8 +71,8 @@ func TestKafkaSchema(t *testing.T) { kafkaName := randName("kafka-schema") schemaName := randName("kafka-schema") subjectName := randName("kafka-schema") - yml := getKafkaSchemaYaml(testProject, kafkaName, schemaName, subjectName, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getKafkaSchemaYaml(cfg.Project, kafkaName, schemaName, subjectName, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -87,7 +87,7 @@ func TestKafkaSchema(t *testing.T) { // THEN // Kafka test - kafkaAvn, err := avnClient.Services.Get(ctx, testProject, kafkaName) + kafkaAvn, err := avnClient.Services.Get(ctx, cfg.Project, kafkaName) require.NoError(t, err) assert.Equal(t, kafkaAvn.Name, kafka.GetName()) assert.Equal(t, "RUNNING", kafka.Status.State) @@ -137,7 +137,7 @@ func TestKafkaSchema(t *testing.T) { // Validates deleting, because deleted kafka drops schemas, and we want be sure deletion works assert.NoError(t, s.Delete(schema, func() error { - _, err := avnClient.KafkaSubjectSchemas.Get(ctx, testProject, kafkaName, subjectName, 1) + _, err := avnClient.KafkaSubjectSchemas.Get(ctx, cfg.Project, kafkaName, subjectName, 1) return err })) } diff --git a/tests/kafkatopic_test.go b/tests/kafkatopic_test.go index 3975cfd1b..9f95abe12 100644 --- a/tests/kafkatopic_test.go +++ b/tests/kafkatopic_test.go @@ -44,9 +44,9 @@ spec: partitions: 1 config: min_cleanable_dirty_ratio: 0.2 - local_retention_bytes: 1024 - local_retention_ms: 1000000 - remote_storage_enable: true + retention_bytes: 3 + local_retention_bytes: 1 + local_retention_ms: 100 --- @@ -76,8 +76,8 @@ func TestKafkaTopic(t *testing.T) { // GIVEN ctx := context.Background() ksName := randName("kafka-topic") - yml := getKafkaTopicNameYaml(testProject, ksName, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getKafkaTopicNameYaml(cfg.Project, ksName, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -99,7 +99,7 @@ func TestKafkaTopic(t *testing.T) { // THEN // Validates Kafka - ksAvn, err := avnClient.Services.Get(ctx, testProject, ksName) + ksAvn, err := avnClient.Services.Get(ctx, cfg.Project, ksName) require.NoError(t, err) assert.Equal(t, ksAvn.Name, ks.GetName()) assert.Equal(t, ksAvn.State, ks.Status.State) @@ -111,7 +111,7 @@ func TestKafkaTopic(t *testing.T) { assert.True(t, meta.IsStatusConditionTrue(barTopic.Status.Conditions, "Running")) // KafkaTopic with name `foo-topic` - fooAvn, err := avnClient.KafkaTopics.Get(ctx, testProject, ksName, fooTopic.GetTopicName()) + fooAvn, err := avnClient.KafkaTopics.Get(ctx, cfg.Project, ksName, fooTopic.GetTopicName()) require.NoError(t, err) assert.Equal(t, "foo-topic", fooTopic.GetName()) assert.Equal(t, "foo-topic", fooTopic.GetTopicName()) @@ -125,10 +125,9 @@ func TestKafkaTopic(t *testing.T) { require.Equal(t, anyPointer(0.2), fooTopic.Spec.Config.MinCleanableDirtyRatio) require.Equal(t, anyPointer(int64(1024)), fooTopic.Spec.Config.LocalRetentionBytes) require.Equal(t, anyPointer(int64(1000000)), fooTopic.Spec.Config.LocalRetentionMs) - require.Equal(t, anyPointer(true), fooTopic.Spec.Config.RemoteStorageEnable) // KafkaTopic with name `bar_topic_name_with_underscores` - barAvn, err := avnClient.KafkaTopics.Get(ctx, testProject, ksName, barTopic.GetTopicName()) + barAvn, err := avnClient.KafkaTopics.Get(ctx, cfg.Project, ksName, barTopic.GetTopicName()) require.NoError(t, err) assert.Equal(t, "bar-topic", barTopic.GetName()) assert.Equal(t, "bar_topic_name_with_underscores", barTopic.GetTopicName()) @@ -149,12 +148,12 @@ func TestKafkaTopic(t *testing.T) { // if service is deleted, topic is destroyed in Aiven. No service — no topic. No topic — no topic. // And we make sure that controller can delete topic itself assert.NoError(t, s.Delete(fooTopic, func() error { - _, err = avnClient.KafkaTopics.Get(ctx, testProject, ksName, fooTopic.Name) + _, err = avnClient.KafkaTopics.Get(ctx, cfg.Project, ksName, fooTopic.Name) return err })) assert.NoError(t, s.Delete(barTopic, func() error { - _, err = avnClient.KafkaTopics.Get(ctx, testProject, ksName, "bar_topic_name_with_underscores") + _, err = avnClient.KafkaTopics.Get(ctx, cfg.Project, ksName, "bar_topic_name_with_underscores") return err })) } diff --git a/tests/mysql_test.go b/tests/mysql_test.go index 8576a68aa..427ffd644 100644 --- a/tests/mysql_test.go +++ b/tests/mysql_test.go @@ -50,8 +50,8 @@ func TestMySQL(t *testing.T) { // GIVEN ctx := context.Background() name := randName("mysql") - yml := getMySQLYaml(testProject, name, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getMySQLYaml(cfg.Project, name, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -65,7 +65,7 @@ func TestMySQL(t *testing.T) { require.NoError(t, s.GetRunning(ms, name)) // THEN - msAvn, err := avnClient.Services.Get(ctx, testProject, name) + msAvn, err := avnClient.Services.Get(ctx, cfg.Project, name) require.NoError(t, err) assert.Equal(t, msAvn.Name, ms.GetName()) assert.Equal(t, "RUNNING", ms.Status.State) @@ -75,7 +75,7 @@ func TestMySQL(t *testing.T) { assert.Equal(t, "100Gib", ms.Spec.DiskSpace) assert.Equal(t, 102400, msAvn.DiskSpaceMB) assert.Equal(t, map[string]string{"env": "test", "instance": "foo"}, ms.Spec.Tags) - msResp, err := avnClient.ServiceTags.Get(ctx, testProject, name) + msResp, err := avnClient.ServiceTags.Get(ctx, cfg.Project, name) require.NoError(t, err) assert.Equal(t, msResp.Tags, ms.Spec.Tags) diff --git a/tests/opensearch_test.go b/tests/opensearch_test.go index 0d75ad697..23db61029 100644 --- a/tests/opensearch_test.go +++ b/tests/opensearch_test.go @@ -55,8 +55,8 @@ func TestOpenSearch(t *testing.T) { // GIVEN ctx := context.Background() name := randName("opensearch") - yml := getOpenSearchYaml(testProject, name, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getOpenSearchYaml(cfg.Project, name, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -70,7 +70,7 @@ func TestOpenSearch(t *testing.T) { require.NoError(t, s.GetRunning(os, name)) // THEN - osAvn, err := avnClient.Services.Get(ctx, testProject, name) + osAvn, err := avnClient.Services.Get(ctx, cfg.Project, name) require.NoError(t, err) assert.Equal(t, osAvn.Name, os.GetName()) assert.Equal(t, "RUNNING", os.Status.State) @@ -80,7 +80,7 @@ func TestOpenSearch(t *testing.T) { assert.Equal(t, "240Gib", os.Spec.DiskSpace) assert.Equal(t, 245760, osAvn.DiskSpaceMB) assert.Equal(t, map[string]string{"env": "test", "instance": "foo"}, os.Spec.Tags) - osResp, err := avnClient.ServiceTags.Get(ctx, testProject, name) + osResp, err := avnClient.ServiceTags.Get(ctx, cfg.Project, name) require.NoError(t, err) assert.Equal(t, osResp.Tags, os.Spec.Tags) diff --git a/tests/postgresql_test.go b/tests/postgresql_test.go index 6c0b1982a..f0dc986c7 100644 --- a/tests/postgresql_test.go +++ b/tests/postgresql_test.go @@ -69,8 +69,8 @@ func TestPgReadReplica(t *testing.T) { ctx := context.Background() masterName := randName("pg-master") replicaName := randName("pg-replica") - yml := getPgReadReplicaYaml(testProject, masterName, replicaName, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getPgReadReplicaYaml(cfg.Project, masterName, replicaName, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -88,7 +88,7 @@ func TestPgReadReplica(t *testing.T) { // THEN // Validates instances - masterAvn, err := avnClient.Services.Get(ctx, testProject, masterName) + masterAvn, err := avnClient.Services.Get(ctx, cfg.Project, masterName) require.NoError(t, err) assert.Equal(t, masterAvn.Name, master.GetName()) assert.Equal(t, "RUNNING", master.Status.State) @@ -98,11 +98,11 @@ func TestPgReadReplica(t *testing.T) { assert.NotNil(t, masterAvn.UserConfig) // "Aiven instance has defaults set" assert.Nil(t, master.Spec.UserConfig) assert.Equal(t, map[string]string{"env": "prod", "instance": "master"}, master.Spec.Tags) - masterResp, err := avnClient.ServiceTags.Get(ctx, testProject, masterName) + masterResp, err := avnClient.ServiceTags.Get(ctx, cfg.Project, masterName) require.NoError(t, err) assert.Equal(t, masterResp.Tags, master.Spec.Tags) - replicaAvn, err := avnClient.Services.Get(ctx, testProject, replicaName) + replicaAvn, err := avnClient.Services.Get(ctx, cfg.Project, replicaName) require.NoError(t, err) assert.Equal(t, replicaAvn.Name, replica.GetName()) assert.Equal(t, "RUNNING", replica.Status.State) @@ -110,7 +110,7 @@ func TestPgReadReplica(t *testing.T) { assert.Equal(t, replicaAvn.Plan, replica.Spec.Plan) assert.Equal(t, replicaAvn.CloudName, replica.Spec.CloudName) assert.Equal(t, map[string]string{"env": "test", "instance": "replica"}, replica.Spec.Tags) - replicaResp, err := avnClient.ServiceTags.Get(ctx, testProject, replicaName) + replicaResp, err := avnClient.ServiceTags.Get(ctx, cfg.Project, replicaName) require.NoError(t, err) assert.Equal(t, replicaResp.Tags, replica.Spec.Tags) @@ -185,8 +185,8 @@ func TestPgCustomPrefix(t *testing.T) { // GIVEN ctx := context.Background() pgName := randName("secret-prefix") - yml := getPgCustomPrefixYaml(testProject, pgName, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getPgCustomPrefixYaml(cfg.Project, pgName, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -201,7 +201,7 @@ func TestPgCustomPrefix(t *testing.T) { // THEN // Validates instance - pgAvn, err := avnClient.Services.Get(ctx, testProject, pgName) + pgAvn, err := avnClient.Services.Get(ctx, cfg.Project, pgName) require.NoError(t, err) assert.Equal(t, pgAvn.Name, pg.GetName()) assert.Equal(t, "RUNNING", pg.Status.State) @@ -209,7 +209,7 @@ func TestPgCustomPrefix(t *testing.T) { assert.Equal(t, pgAvn.Plan, pg.Spec.Plan) assert.Equal(t, pgAvn.CloudName, pg.Spec.CloudName) assert.Equal(t, map[string]string{"env": "prod", "instance": "pg"}, pg.Spec.Tags) - masterResp, err := avnClient.ServiceTags.Get(ctx, testProject, pgName) + masterResp, err := avnClient.ServiceTags.Get(ctx, cfg.Project, pgName) require.NoError(t, err) assert.Equal(t, masterResp.Tags, pg.Spec.Tags) diff --git a/tests/project_test.go b/tests/project_test.go index 6646eeaf2..07ef338df 100644 --- a/tests/project_test.go +++ b/tests/project_test.go @@ -39,7 +39,7 @@ func TestProject(t *testing.T) { ctx := context.Background() name := randName("project") yml := getProjectYaml(name) - s := NewSession(k8sClient, avnClient, testProject) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() diff --git a/tests/projectvpc_test.go b/tests/projectvpc_test.go index 816782b2f..afbe92f2e 100644 --- a/tests/projectvpc_test.go +++ b/tests/projectvpc_test.go @@ -73,8 +73,8 @@ func TestProjectVPCID(t *testing.T) { ctx := context.Background() vpcName1 := randName("project-vpc-id") vpcName2 := randName("project-vpc-id") - vpcYaml := getProjectVPCsYaml(testProject, vpcName1, testSecondaryCloudName, vpcName2, testTertiaryCloudName) - vpcSession := NewSession(k8sClient, avnClient, testProject) + vpcYaml := getProjectVPCsYaml(cfg.Project, vpcName1, cfg.SecondaryCloudName, vpcName2, cfg.TertiaryCloudName) + vpcSession := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer vpcSession.Destroy() @@ -92,7 +92,7 @@ func TestProjectVPCID(t *testing.T) { // THEN // Validates VPC - vpc1Avn, err := avnClient.VPCs.Get(ctx, testProject, vpc1.Status.ID) + vpc1Avn, err := avnClient.VPCs.Get(ctx, cfg.Project, vpc1.Status.ID) require.NoError(t, err) assert.Equal(t, "ACTIVE", vpc1Avn.State) assert.Equal(t, vpc1Avn.State, vpc1.Status.State) @@ -100,7 +100,7 @@ func TestProjectVPCID(t *testing.T) { assert.Equal(t, "10.0.0.0/24", vpc1.Spec.NetworkCidr) assert.Equal(t, vpc1Avn.NetworkCIDR, vpc1.Spec.NetworkCidr) - vpc2Avn, err := avnClient.VPCs.Get(ctx, testProject, vpc2.Status.ID) + vpc2Avn, err := avnClient.VPCs.Get(ctx, cfg.Project, vpc2.Status.ID) require.NoError(t, err) assert.Equal(t, "ACTIVE", vpc2Avn.State) assert.Equal(t, vpc2Avn.State, vpc2.Status.State) @@ -110,8 +110,8 @@ func TestProjectVPCID(t *testing.T) { // Creates Kafka with given vpcID kafkaName := randName("project-vpc-id") - kafkaYaml := getKafkaForProjectVPCYaml(testProject, vpc1.Status.ID, kafkaName, testSecondaryCloudName) - kafkaSession := NewSession(k8sClient, avnClient, testProject) + kafkaYaml := getKafkaForProjectVPCYaml(cfg.Project, vpc1.Status.ID, kafkaName, cfg.SecondaryCloudName) + kafkaSession := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer kafkaSession.Destroy() @@ -125,7 +125,7 @@ func TestProjectVPCID(t *testing.T) { require.NoError(t, kafkaSession.GetRunning(kafka, kafkaName)) // THEN - kafkaAvn, err := avnClient.Services.Get(ctx, testProject, kafkaName) + kafkaAvn, err := avnClient.Services.Get(ctx, cfg.Project, kafkaName) require.NoError(t, err) assert.Equal(t, kafkaAvn.Name, kafka.GetName()) assert.Equal(t, "RUNNING", kafka.Status.State) @@ -138,7 +138,7 @@ func TestProjectVPCID(t *testing.T) { assert.Equal(t, anyPointer(vpc1.Status.ID), kafkaAvn.ProjectVPCID) // Migrates the service to vpc2 - kafkaYamlUpd := getKafkaForProjectVPCYaml(testProject, vpc2.Status.ID, kafkaName, testTertiaryCloudName) + kafkaYamlUpd := getKafkaForProjectVPCYaml(cfg.Project, vpc2.Status.ID, kafkaName, cfg.TertiaryCloudName) require.NoError(t, kafkaSession.Apply(kafkaYamlUpd)) // This migration takes too long, so we don't wait it's being in the RUNNING state in kube @@ -148,13 +148,13 @@ func TestProjectVPCID(t *testing.T) { // Gets Aiven object var kafkaAvnUpd *aiven.Service require.NoError(t, retryForever(ctx, fmt.Sprintf("migrate %s to VPC with ID %s", kafkaName, vpc2.Status.ID), func() (bool, error) { - kafkaAvnUpd, err = avnClient.Services.Get(ctx, testProject, kafkaName) + kafkaAvnUpd, err = avnClient.Services.Get(ctx, cfg.Project, kafkaName) if err != nil { return false, err } // Just waits object being updated in Aiven - return kafkaAvnUpd.CloudName != testTertiaryCloudName, nil + return kafkaAvnUpd.CloudName != cfg.TertiaryCloudName, nil })) // Gets kube object diff --git a/tests/redis_test.go b/tests/redis_test.go index 8133ca074..41b7b8900 100644 --- a/tests/redis_test.go +++ b/tests/redis_test.go @@ -47,8 +47,8 @@ func TestRedis(t *testing.T) { // GIVEN ctx := context.Background() name := randName("redis") - yml := getRedisYaml(testProject, name, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getRedisYaml(cfg.Project, name, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -62,7 +62,7 @@ func TestRedis(t *testing.T) { require.NoError(t, s.GetRunning(rs, name)) // THEN - rsAvn, err := avnClient.Services.Get(ctx, testProject, name) + rsAvn, err := avnClient.Services.Get(ctx, cfg.Project, name) require.NoError(t, err) assert.Equal(t, rsAvn.Name, rs.GetName()) assert.Equal(t, "RUNNING", rs.Status.State) @@ -70,7 +70,7 @@ func TestRedis(t *testing.T) { assert.Equal(t, rsAvn.Plan, rs.Spec.Plan) assert.Equal(t, rsAvn.CloudName, rs.Spec.CloudName) assert.Equal(t, map[string]string{"env": "test", "instance": "foo"}, rs.Spec.Tags) - rsResp, err := avnClient.ServiceTags.Get(ctx, testProject, name) + rsResp, err := avnClient.ServiceTags.Get(ctx, cfg.Project, name) require.NoError(t, err) assert.Equal(t, rsResp.Tags, rs.Spec.Tags) diff --git a/tests/service_opts_test.go b/tests/service_opts_test.go index 91446de4e..0c39311df 100644 --- a/tests/service_opts_test.go +++ b/tests/service_opts_test.go @@ -44,8 +44,8 @@ func TestServiceTechnicalEmails(t *testing.T) { // GIVEN ctx := context.Background() name := randName("grafana") - yml := getTechnicalEmailsYaml(testProject, name, testPrimaryCloudName, true) - s := NewSession(k8sClient, avnClient, testProject) + yml := getTechnicalEmailsYaml(cfg.Project, name, cfg.PrimaryCloudName, true) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -60,14 +60,14 @@ func TestServiceTechnicalEmails(t *testing.T) { // THEN // Technical emails are set - grafanaAvn, err := avnClient.Services.Get(ctx, testProject, name) + grafanaAvn, err := avnClient.Services.Get(ctx, cfg.Project, name) require.NoError(t, err) assert.Len(t, grafana.Spec.TechnicalEmails, 1) assert.Equal(t, "test@example.com", grafanaAvn.TechnicalEmails[0].Email) // WHEN // Technical emails are removed from manifest - updatedYml := getTechnicalEmailsYaml(testProject, name, testPrimaryCloudName, false) + updatedYml := getTechnicalEmailsYaml(cfg.Project, name, cfg.PrimaryCloudName, false) // Applies updated manifest require.NoError(t, s.Apply(updatedYml)) @@ -77,7 +77,7 @@ func TestServiceTechnicalEmails(t *testing.T) { // THEN // Technical emails are removed from service - grafanaAvnUpdated, err := avnClient.Services.Get(ctx, testProject, name) + grafanaAvnUpdated, err := avnClient.Services.Get(ctx, cfg.Project, name) require.NoError(t, err) assert.Empty(t, grafanaAvnUpdated.TechnicalEmails) } @@ -110,11 +110,11 @@ func runTest(t *testing.T, scenario TestScenario) { defer recoverPanic(t) // GIVEN - baseYaml := getConnInfoBaseYaml(testProject, scenario.serviceName, testPrimaryCloudName) + baseYaml := getConnInfoBaseYaml(cfg.Project, scenario.serviceName, cfg.PrimaryCloudName) createYaml := getYamlWithDisabledOption(baseYaml, scenario.connInfoSecretTargetDisabledChange[0]) updateYaml := getYamlWithDisabledOption(baseYaml, scenario.connInfoSecretTargetDisabledChange[1]) - s := NewSession(k8sClient, avnClient, testProject) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() diff --git a/tests/serviceintegration_test.go b/tests/serviceintegration_test.go index d0e337626..197c9672f 100644 --- a/tests/serviceintegration_test.go +++ b/tests/serviceintegration_test.go @@ -83,8 +83,8 @@ func TestServiceIntegrationClickhousePostgreSQL(t *testing.T) { pgName := randName("clickhouse-postgresql") siName := randName("clickhouse-postgresql") - yml := getClickhousePostgreSQLYaml(testProject, chName, pgName, siName, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getClickhousePostgreSQLYaml(cfg.Project, chName, pgName, siName, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -105,7 +105,7 @@ func TestServiceIntegrationClickhousePostgreSQL(t *testing.T) { // THEN // Validates Clickhouse - chAvn, err := avnClient.Services.Get(ctx, testProject, chName) + chAvn, err := avnClient.Services.Get(ctx, cfg.Project, chName) require.NoError(t, err) assert.Equal(t, chAvn.Name, ch.GetName()) assert.Equal(t, chAvn.State, ch.Status.State) @@ -115,7 +115,7 @@ func TestServiceIntegrationClickhousePostgreSQL(t *testing.T) { assert.Equal(t, chAvn.MaintenanceWindow.TimeOfDay, ch.Spec.MaintenanceWindowTime) // Validates PostgreSQL - pgAvn, err := avnClient.Services.Get(ctx, testProject, pgName) + pgAvn, err := avnClient.Services.Get(ctx, cfg.Project, pgName) require.NoError(t, err) assert.Equal(t, pgAvn.Name, pg.GetName()) assert.Equal(t, pgAvn.State, pg.Status.State) @@ -126,7 +126,7 @@ func TestServiceIntegrationClickhousePostgreSQL(t *testing.T) { assert.Equal(t, pgAvn.UserConfig["pg_version"].(string), *pg.Spec.UserConfig.PgVersion) // Validates ServiceIntegration - siAvn, err := avnClient.ServiceIntegrations.Get(ctx, testProject, si.Status.ID) + siAvn, err := avnClient.ServiceIntegrations.Get(ctx, cfg.Project, si.Status.ID) require.NoError(t, err) assert.Equal(t, "clickhouse_postgresql", siAvn.IntegrationType) assert.Equal(t, siAvn.IntegrationType, si.Spec.IntegrationType) @@ -198,8 +198,8 @@ func TestServiceIntegrationKafkaLogs(t *testing.T) { ktName := randName("kafka-logs") siName := randName("kafka-logs") - yml := getKafkaLogsYaml(testProject, ksName, ktName, siName, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getKafkaLogsYaml(cfg.Project, ksName, ktName, siName, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -220,7 +220,7 @@ func TestServiceIntegrationKafkaLogs(t *testing.T) { // THEN // Validates Kafka - ksAvn, err := avnClient.Services.Get(ctx, testProject, ksName) + ksAvn, err := avnClient.Services.Get(ctx, cfg.Project, ksName) require.NoError(t, err) assert.Equal(t, ksAvn.Name, ks.GetName()) assert.Equal(t, ksAvn.State, ks.Status.State) @@ -228,7 +228,7 @@ func TestServiceIntegrationKafkaLogs(t *testing.T) { assert.Equal(t, ksAvn.CloudName, ks.Spec.CloudName) // Validates KafkaTopic - ktAvn, err := avnClient.KafkaTopics.Get(ctx, testProject, ksName, ktName) + ktAvn, err := avnClient.KafkaTopics.Get(ctx, cfg.Project, ksName, ktName) require.NoError(t, err) assert.Equal(t, ktAvn.TopicName, kt.GetName()) assert.Equal(t, ktAvn.State, kt.Status.State) @@ -236,7 +236,7 @@ func TestServiceIntegrationKafkaLogs(t *testing.T) { assert.Len(t, ktAvn.Partitions, kt.Spec.Partitions) // Validates ServiceIntegration - siAvn, err := avnClient.ServiceIntegrations.Get(ctx, testProject, si.Status.ID) + siAvn, err := avnClient.ServiceIntegrations.Get(ctx, cfg.Project, si.Status.ID) require.NoError(t, err) assert.Equal(t, "kafka_logs", siAvn.IntegrationType) assert.Equal(t, siAvn.IntegrationType, si.Spec.IntegrationType) @@ -318,8 +318,8 @@ func TestServiceIntegrationKafkaConnect(t *testing.T) { kcName := randName("kafka-connect") siName := randName("kafka-connect") - yml := getSIKafkaConnectYaml(testProject, ksName, kcName, siName, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getSIKafkaConnectYaml(cfg.Project, ksName, kcName, siName, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -340,7 +340,7 @@ func TestServiceIntegrationKafkaConnect(t *testing.T) { // THEN // Validates Kafka - ksAvn, err := avnClient.Services.Get(ctx, testProject, ksName) + ksAvn, err := avnClient.Services.Get(ctx, cfg.Project, ksName) require.NoError(t, err) assert.Equal(t, ksAvn.Name, ks.GetName()) assert.Equal(t, ksAvn.State, ks.Status.State) @@ -348,7 +348,7 @@ func TestServiceIntegrationKafkaConnect(t *testing.T) { assert.Equal(t, ksAvn.CloudName, ks.Spec.CloudName) // Validates KafkaConnect - kcAvn, err := avnClient.Services.Get(ctx, testProject, kcName) + kcAvn, err := avnClient.Services.Get(ctx, cfg.Project, kcName) require.NoError(t, err) assert.Equal(t, kcAvn.Name, kc.GetName()) assert.Equal(t, kcAvn.State, kc.Status.State) @@ -358,7 +358,7 @@ func TestServiceIntegrationKafkaConnect(t *testing.T) { assert.True(t, *kc.Spec.UserConfig.PublicAccess.KafkaConnect) // Validates ServiceIntegration - siAvn, err := avnClient.ServiceIntegrations.Get(ctx, testProject, si.Status.ID) + siAvn, err := avnClient.ServiceIntegrations.Get(ctx, cfg.Project, si.Status.ID) require.NoError(t, err) assert.Equal(t, "kafka_connect", siAvn.IntegrationType) assert.Equal(t, siAvn.IntegrationType, si.Spec.IntegrationType) @@ -426,8 +426,8 @@ func TestServiceIntegrationDatadog(t *testing.T) { pgName := randName("datadog") siName := randName("datadog") - yml := getDatadogYaml(testProject, pgName, siName, endpointID, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getDatadogYaml(cfg.Project, pgName, siName, endpointID, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -445,14 +445,14 @@ func TestServiceIntegrationDatadog(t *testing.T) { // THEN // Validates PostgreSQL - pgAvn, err := avnClient.Services.Get(ctx, testProject, pgName) + pgAvn, err := avnClient.Services.Get(ctx, cfg.Project, pgName) require.NoError(t, err) assert.Equal(t, pgAvn.Name, pg.GetName()) assert.Equal(t, pgAvn.State, pg.Status.State) assert.Equal(t, pgAvn.Plan, pg.Spec.Plan) // Validates Datadog - siAvn, err := avnClient.ServiceIntegrations.Get(ctx, testProject, si.Status.ID) + siAvn, err := avnClient.ServiceIntegrations.Get(ctx, cfg.Project, si.Status.ID) require.NoError(t, err) assert.Equal(t, "datadog", siAvn.IntegrationType) assert.Equal(t, siAvn.IntegrationType, si.Spec.IntegrationType) @@ -500,10 +500,10 @@ func TestWebhookMultipleUserConfigsDenied(t *testing.T) { // GIVEN siName := randName("datadog") - yml := getWebhookMultipleUserConfigsDeniedYaml(testProject, siName) + yml := getWebhookMultipleUserConfigsDeniedYaml(cfg.Project, siName) // WHEN - s := NewSession(k8sClient, avnClient, testProject) + s := NewSession(k8sClient, avnClient, cfg.Project) // THEN err := s.Apply(yml) diff --git a/tests/serviceuser_test.go b/tests/serviceuser_test.go index a0f5faab2..9ca48e0e6 100644 --- a/tests/serviceuser_test.go +++ b/tests/serviceuser_test.go @@ -63,8 +63,8 @@ func TestServiceUserKafka(t *testing.T) { ctx := context.Background() kafkaName := randName("service-user") userName := randName("service-user") - yml := getServiceUserKafkaYaml(testProject, kafkaName, userName, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getServiceUserKafkaYaml(cfg.Project, kafkaName, userName, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterward defer s.Destroy() @@ -82,7 +82,7 @@ func TestServiceUserKafka(t *testing.T) { // THEN // Validates Kafka - kafkaAvn, err := avnClient.Services.Get(ctx, testProject, kafkaName) + kafkaAvn, err := avnClient.Services.Get(ctx, cfg.Project, kafkaName) require.NoError(t, err) assert.Equal(t, kafkaAvn.Name, kafka.GetName()) assert.Equal(t, "RUNNING", kafka.Status.State) @@ -91,7 +91,7 @@ func TestServiceUserKafka(t *testing.T) { assert.Equal(t, kafkaAvn.CloudName, kafka.Spec.CloudName) // Validates ServiceUser - userAvn, err := avnClient.ServiceUsers.Get(ctx, testProject, kafkaName, userName) + userAvn, err := avnClient.ServiceUsers.Get(ctx, cfg.Project, kafkaName, userName) require.NoError(t, err) assert.Equal(t, userName, user.GetName()) assert.Equal(t, userName, userAvn.Username) @@ -132,7 +132,7 @@ func TestServiceUserKafka(t *testing.T) { // if service is deleted, pool is destroyed in Aiven. No service — no pool. No pool — no pool. // And we make sure that the controller can delete db itself assert.NoError(t, s.Delete(user, func() error { - _, err = avnClient.ServiceUsers.Get(ctx, testProject, kafkaName, userName) + _, err = avnClient.ServiceUsers.Get(ctx, cfg.Project, kafkaName, userName) return err })) } @@ -184,8 +184,8 @@ func TestServiceUserPg(t *testing.T) { ctx := context.Background() pgName := randName("connection-pool") userName := randName("connection-pool") - yml := getServiceUserPgYaml(testProject, pgName, userName, testPrimaryCloudName) - s := NewSession(k8sClient, avnClient, testProject) + yml := getServiceUserPgYaml(cfg.Project, pgName, userName, cfg.PrimaryCloudName) + s := NewSession(k8sClient, avnClient, cfg.Project) // Cleans test afterwards defer s.Destroy() @@ -203,7 +203,7 @@ func TestServiceUserPg(t *testing.T) { // THEN // Validates PostgreSQL - pgAvn, err := avnClient.Services.Get(ctx, testProject, pgName) + pgAvn, err := avnClient.Services.Get(ctx, cfg.Project, pgName) require.NoError(t, err) assert.Equal(t, pgAvn.Name, pg.GetName()) assert.Equal(t, "RUNNING", pg.Status.State) @@ -212,7 +212,7 @@ func TestServiceUserPg(t *testing.T) { assert.Equal(t, pgAvn.CloudName, pg.Spec.CloudName) // Validates ServiceUser - userAvn, err := avnClient.ServiceUsers.Get(ctx, testProject, pgName, userName) + userAvn, err := avnClient.ServiceUsers.Get(ctx, cfg.Project, pgName, userName) require.NoError(t, err) assert.Equal(t, userName, user.GetName()) assert.Equal(t, userName, userAvn.Username) @@ -247,7 +247,7 @@ func TestServiceUserPg(t *testing.T) { // if service is deleted, pool is destroyed in Aiven. No service — no pool. No pool — no pool. // And we make sure that the controller can delete db itself assert.NoError(t, s.Delete(user, func() error { - _, err = avnClient.ServiceUsers.Get(ctx, testProject, pgName, userName) + _, err = avnClient.ServiceUsers.Get(ctx, cfg.Project, pgName, userName) return err })) } diff --git a/tests/session.go b/tests/session.go index 942a23ced..e592fcd9e 100644 --- a/tests/session.go +++ b/tests/session.go @@ -115,7 +115,7 @@ func (s *session) GetRunning(obj client.Object, keys ...string) error { err := s.k8s.Get(ctx, key, obj) if err != nil { // The error is quite verbose - log.Printf("waiting resource running: %s", err) + log.Printf("waiting resource %q running: %s", key, err) // Do not retry kube errors return isNotFound(err), err @@ -206,21 +206,29 @@ func (s *session) recover() { func retryForever(ctx context.Context, operation string, f func() (bool, error)) (err error) { retry := false - log.Printf("Starting operation: %s\n", operation) + log.Printf("Operation %q started\n", operation) +outer: for { select { case <-ctx.Done(): - return fmt.Errorf("context timeout while retrying operation: %s, error=%q", operation, err) + err = ctx.Err() + break outer case <-time.After(retryInterval): retry, err = f() - if retry { - continue + if !retry { + break outer } - log.Printf("Operation %s finished\n", operation) - return err } } + + if err != nil { + log.Printf("Operation %q failed: %s\n", operation, err) + return err + } + + log.Printf("Operation %q succeeded\n", operation) + return nil } const ( diff --git a/tests/suite_test.go b/tests/suite_test.go index 377ec8c98..39d7824a7 100644 --- a/tests/suite_test.go +++ b/tests/suite_test.go @@ -6,10 +6,10 @@ import ( "log" "os" "runtime/debug" - "strconv" "testing" "github.com/aiven/aiven-go-client/v2" + "github.com/kelseyhightower/envconfig" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/scheme" @@ -23,13 +23,9 @@ import ( ) var ( - testEnv *envtest.Environment - testProject string - testPrimaryCloudName string - testSecondaryCloudName string - testTertiaryCloudName string - k8sClient client.Client - avnClient *aiven.Client + cfg *testConfig + k8sClient client.Client + avnClient *aiven.Client ) const ( @@ -37,57 +33,50 @@ const ( secretRefKey = "token" ) +type testConfig struct { + Token string `envconfig:"AIVEN_TOKEN" required:"true"` + Project string `envconfig:"AIVEN_PROJECT_NAME" required:"true"` + PrimaryCloudName string `envconfig:"AIVEN_CLOUD_NAME" default:"google-europe-west1"` + SecondaryCloudName string `envconfig:"AIVEN_SECONDARY_CLOUD_NAME" default:"google-europe-west2"` + TertiaryCloudName string `envconfig:"AIVEN_TERTIARY_CLOUD_NAME" default:"google-europe-west3"` + DebugLogging bool `envconfig:"ENABLE_DEBUG_LOGGING"` +} + func TestMain(m *testing.M) { - err := setupSuite() + env, err := setupSuite() if err != nil { log.Fatal(err) } - defer teardownSuite() + defer teardownSuite(env) os.Exit(m.Run()) } -func teardownSuite() { - err := testEnv.Stop() +func teardownSuite(env *envtest.Environment) { + if env == nil { + return + } + + err := env.Stop() if err != nil { log.Printf("failed to teardown: %s", err) } } -func setupSuite() error { - aivenToken := os.Getenv("AIVEN_TOKEN") - if aivenToken == "" { - return fmt.Errorf("missing AIVEN_TOKEN set") - } - - testProject = os.Getenv("AIVEN_PROJECT_NAME") - if testProject == "" { - return fmt.Errorf("missing AIVEN_PROJECT_NAME set") - } - - testPrimaryCloudName = os.Getenv("AIVEN_CLOUD_NAME") - if testPrimaryCloudName == "" { - testPrimaryCloudName = "google-europe-west1" - } - - testSecondaryCloudName = os.Getenv("AIVEN_SECONDARY_CLOUD_NAME") - if testSecondaryCloudName == "" { - testSecondaryCloudName = "google-europe-west2" - } - - testTertiaryCloudName = os.Getenv("AIVEN_TERTIARY_CLOUD_NAME") - if testTertiaryCloudName == "" { - testTertiaryCloudName = "google-europe-west3" +func setupSuite() (*envtest.Environment, error) { + cfg = new(testConfig) + err := envconfig.Process("", cfg) + if err != nil { + return nil, err } - enableLogs, _ := strconv.ParseBool(os.Getenv("ENABLE_DEBUG_LOGGING")) - if enableLogs { + if cfg.DebugLogging { ctrl.SetLogger(zap.New(func(o *zap.Options) { o.Development = true })) } - testEnv = &envtest.Environment{ + env := &envtest.Environment{ ErrorIfCRDPathMissing: true, CRDDirectoryPaths: []string{"../config/crd/bases"}, WebhookInstallOptions: envtest.WebhookInstallOptions{ @@ -95,29 +84,29 @@ func setupSuite() error { }, } - cfg, err := testEnv.Start() + c, err := env.Start() if err != nil { - return err + return nil, err } err = v1alpha1.AddToScheme(scheme.Scheme) if err != nil { - return err + return nil, err } - avnClient, err = controllers.NewAivenClient(aivenToken) + avnClient, err = controllers.NewAivenClient(cfg.Token) if err != nil { - return err + return nil, err } - mgr, err := ctrl.NewManager(cfg, ctrl.Options{ + mgr, err := ctrl.NewManager(c, ctrl.Options{ Scheme: scheme.Scheme, MetricsBindAddress: "0", - CertDir: testEnv.WebhookInstallOptions.LocalServingCertDir, - Port: testEnv.WebhookInstallOptions.LocalServingPort, + CertDir: env.WebhookInstallOptions.LocalServingCertDir, + Port: env.WebhookInstallOptions.LocalServingPort, }) if err != nil { - return err + return nil, err } k8sClient = mgr.GetClient() secret := &corev1.Secret{ @@ -126,24 +115,24 @@ func setupSuite() error { Namespace: defaultNamespace, }, StringData: map[string]string{ - secretRefKey: aivenToken, + secretRefKey: cfg.Token, }, } ctx := context.Background() err = k8sClient.Create(ctx, secret) if err != nil { - return err + return nil, err } - err = controllers.SetupControllers(mgr, aivenToken) + err = controllers.SetupControllers(mgr, cfg.Token) if err != nil { - return fmt.Errorf("unable to setup controllers: %w", err) + return nil, fmt.Errorf("unable to setup controllers: %w", err) } err = v1alpha1.SetupWebhooks(mgr) if err != nil { - return fmt.Errorf("unable to setup webhooks: %w", err) + return nil, fmt.Errorf("unable to setup webhooks: %w", err) } go func() { @@ -152,7 +141,7 @@ func setupSuite() error { log.Fatal(err) } }() - return nil + return env, nil } func recoverPanic(t *testing.T) {