Skip to content

Commit

Permalink
feat: convert simple ServiceGet calls to generated client
Browse files Browse the repository at this point in the history
  • Loading branch information
rriski committed Sep 3, 2024
1 parent 96e0899 commit b654304
Show file tree
Hide file tree
Showing 20 changed files with 76 additions and 77 deletions.
6 changes: 3 additions & 3 deletions tests/cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ func TestCassandra(t *testing.T) {
require.NoError(t, s.GetRunning(cs, name))

// THEN
csAvn, err := avnClient.Services.Get(ctx, cfg.Project, name)
csAvn, err := avnGen.ServiceGet(ctx, cfg.Project, name)
require.NoError(t, err)
assert.Equal(t, csAvn.Name, cs.GetName())
assert.Equal(t, csAvn.ServiceName, cs.GetName())
assert.Equal(t, serviceRunningState, cs.Status.State)
assert.Contains(t, serviceRunningStatesAiven, csAvn.State)
assert.Equal(t, csAvn.Plan, cs.Spec.Plan)
assert.Equal(t, csAvn.CloudName, cs.Spec.CloudName)
assert.Equal(t, "450GiB", cs.Spec.DiskSpace)
assert.Equal(t, 460800, csAvn.DiskSpaceMB)
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, cfg.Project, name)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions tests/clickhouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ func TestClickhouse(t *testing.T) {
require.NoError(t, s.GetRunning(ch, chName))

// THEN
chAvn, err := avnClient.Services.Get(ctx, cfg.Project, chName)
chAvn, err := avnGen.ServiceGet(ctx, cfg.Project, chName)
require.NoError(t, err)
assert.Equal(t, chAvn.Name, ch.GetName())
assert.Equal(t, chAvn.ServiceName, ch.GetName())
assert.Equal(t, serviceRunningState, ch.Status.State)
assert.Contains(t, serviceRunningStatesAiven, chAvn.State)
assert.Equal(t, chAvn.Plan, ch.Spec.Plan)
Expand Down
4 changes: 2 additions & 2 deletions tests/clickhouseuser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ func TestClickhouseUser(t *testing.T) {
require.NoError(t, s.GetRunning(ch, chName))

// THEN
chAvn, err := avnClient.Services.Get(ctx, cfg.Project, chName)
chAvn, err := avnGen.ServiceGet(ctx, cfg.Project, chName)
require.NoError(t, err)
assert.Equal(t, chAvn.Name, ch.GetName())
assert.Equal(t, chAvn.ServiceName, ch.GetName())
assert.Equal(t, serviceRunningState, ch.Status.State)
assert.Contains(t, serviceRunningStatesAiven, chAvn.State)
assert.Equal(t, chAvn.Plan, ch.Spec.Plan)
Expand Down
4 changes: 2 additions & 2 deletions tests/connectionpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ func TestConnectionPool(t *testing.T) {

// THEN
// Validates PostgreSQL
pgAvn, err := avnClient.Services.Get(ctx, cfg.Project, pgName)
pgAvn, err := avnGen.ServiceGet(ctx, cfg.Project, pgName)
require.NoError(t, err)
assert.Equal(t, pgAvn.Name, pg.GetName())
assert.Equal(t, pgAvn.ServiceName, pg.GetName())
assert.Equal(t, serviceRunningState, pg.Status.State)
assert.Contains(t, serviceRunningStatesAiven, pgAvn.State)
assert.Equal(t, pgAvn.Plan, pg.Spec.Plan)
Expand Down
4 changes: 2 additions & 2 deletions tests/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ func TestDatabase(t *testing.T) {

// THEN
// Validates PostgreSQL
pgAvn, err := avnClient.Services.Get(ctx, cfg.Project, pgName)
pgAvn, err := avnGen.ServiceGet(ctx, cfg.Project, pgName)
require.NoError(t, err)
assert.Equal(t, pgAvn.Name, pg.GetName())
assert.Equal(t, pgAvn.ServiceName, pg.GetName())
assert.Equal(t, serviceRunningState, pg.Status.State)
assert.Contains(t, serviceRunningStatesAiven, pgAvn.State)
assert.Equal(t, pgAvn.Plan, pg.Spec.Plan)
Expand Down
4 changes: 2 additions & 2 deletions tests/grafana_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ func TestGrafana(t *testing.T) {
require.NoError(t, s.GetRunning(grafana, name))

// THEN
grafanaAvn, err := avnClient.Services.Get(ctx, cfg.Project, name)
grafanaAvn, err := avnGen.ServiceGet(ctx, cfg.Project, name)
require.NoError(t, err)
assert.Equal(t, grafanaAvn.Name, grafana.GetName())
assert.Equal(t, grafanaAvn.ServiceName, grafana.GetName())
assert.Equal(t, serviceRunningState, grafana.Status.State)
assert.Contains(t, serviceRunningStatesAiven, grafanaAvn.State)
assert.Equal(t, grafanaAvn.Plan, grafana.Spec.Plan)
Expand Down
6 changes: 3 additions & 3 deletions tests/kafka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ func TestKafka(t *testing.T) {
require.NoError(t, s.GetRunning(ks, name))

// THEN
ksAvn, err := avnClient.Services.Get(ctx, cfg.Project, name)
ksAvn, err := avnGen.ServiceGet(ctx, cfg.Project, name)
require.NoError(t, err)
assert.Equal(t, ksAvn.Name, ks.GetName())
assert.Equal(t, ksAvn.ServiceName, ks.GetName())
assert.Equal(t, serviceRunningState, ks.Status.State)
assert.Contains(t, serviceRunningStatesAiven, ksAvn.State)
assert.Equal(t, ksAvn.Plan, ks.Spec.Plan)
assert.Equal(t, ksAvn.CloudName, ks.Spec.CloudName)
assert.Equal(t, "600GiB", ks.Spec.DiskSpace)
assert.Equal(t, 614400, ksAvn.DiskSpaceMB)
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, cfg.Project, name)
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions tests/kafka_with_projectvpc_ref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ func TestKafkaWithProjectVPCRef(t *testing.T) {
require.NoError(t, s.GetRunning(vpc, vpcName))

// THEN
kafkaAvn, err := avnClient.Services.Get(ctx, cfg.Project, kafkaName)
kafkaAvn, err := avnGen.ServiceGet(ctx, cfg.Project, kafkaName)
require.NoError(t, err)
assert.Equal(t, kafkaAvn.Name, kafka.GetName())
assert.Equal(t, kafkaAvn.ServiceName, kafka.GetName())
assert.Equal(t, serviceRunningState, kafka.Status.State)
assert.Contains(t, serviceRunningStatesAiven, kafkaAvn.State)
assert.Equal(t, kafkaAvn.Plan, kafka.Spec.Plan)
Expand All @@ -85,7 +85,7 @@ func TestKafkaWithProjectVPCRef(t *testing.T) {
// Validates VPC
require.NotNil(t, kafka.Spec.ProjectVPCRef)
assert.Equal(t, vpcName, kafka.Spec.ProjectVPCRef.Name)
assert.Equal(t, anyPointer(vpc.Status.ID), kafkaAvn.ProjectVPCID)
assert.Equal(t, anyPointer(vpc.Status.ID), kafkaAvn.ProjectVpcId)

vpcAvn, err := avnClient.VPCs.Get(ctx, cfg.Project, vpc.Status.ID)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions tests/kafkaacl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ func TestKafkaACL(t *testing.T) {

// THEN
// Kafka
kafkaAvn, err := avnClient.Services.Get(ctx, cfg.Project, kafkaName)
kafkaAvn, err := avnGen.ServiceGet(ctx, cfg.Project, kafkaName)
require.NoError(t, err)
assert.Equal(t, kafkaAvn.Name, kafka.GetName())
assert.Equal(t, kafkaAvn.ServiceName, kafka.GetName())
assert.Equal(t, serviceRunningState, kafka.Status.State)
assert.Contains(t, serviceRunningStatesAiven, kafkaAvn.State)
assert.Equal(t, kafkaAvn.Plan, kafka.Spec.Plan)
Expand Down
6 changes: 3 additions & 3 deletions tests/kafkaconnect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
project: %[1]s
cloudName: %[3]s
plan: business-4
userConfig:
kafka_connect:
consumer_isolation_level: read_committed
Expand Down Expand Up @@ -66,9 +66,9 @@ func TestKafkaConnect(t *testing.T) {
require.NoError(t, s.GetRunning(kc, name))

// THEN
kcAvn, err := avnClient.Services.Get(ctx, cfg.Project, name)
kcAvn, err := avnGen.ServiceGet(ctx, cfg.Project, name)
require.NoError(t, err)
assert.Equal(t, kcAvn.Name, kc.GetName())
assert.Equal(t, kcAvn.ServiceName, kc.GetName())
assert.Equal(t, serviceRunningState, kc.Status.State)
assert.Contains(t, serviceRunningStatesAiven, kcAvn.State)
assert.Equal(t, kcAvn.Plan, kc.Spec.Plan)
Expand Down
4 changes: 2 additions & 2 deletions tests/kafkaschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ func TestKafkaSchema(t *testing.T) {

// THEN
// Kafka test
kafkaAvn, err := avnClient.Services.Get(ctx, cfg.Project, kafkaName)
kafkaAvn, err := avnGen.ServiceGet(ctx, cfg.Project, kafkaName)
require.NoError(t, err)
assert.Equal(t, kafkaAvn.Name, kafka.GetName())
assert.Equal(t, kafkaAvn.ServiceName, kafka.GetName())
assert.Equal(t, serviceRunningState, kafka.Status.State)
assert.Contains(t, serviceRunningStatesAiven, kafkaAvn.State)
assert.Equal(t, kafkaAvn.Plan, kafka.Spec.Plan)
Expand Down
4 changes: 2 additions & 2 deletions tests/kafkatopic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ func TestKafkaTopic(t *testing.T) {

// THEN
// Validates Kafka
ksAvn, err := avnClient.Services.Get(ctx, cfg.Project, ksName)
ksAvn, err := avnGen.ServiceGet(ctx, cfg.Project, ksName)
require.NoError(t, err)
assert.Equal(t, ksAvn.Name, ks.GetName())
assert.Equal(t, ksAvn.ServiceName, ks.GetName())
assert.Contains(t, serviceRunningStatesAiven, ksAvn.State)
assert.Equal(t, ksAvn.Plan, ks.Spec.Plan)
assert.Equal(t, ksAvn.CloudName, ks.Spec.CloudName)
Expand Down
6 changes: 3 additions & 3 deletions tests/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ func TestMySQL(t *testing.T) {
require.NoError(t, s.GetRunning(ms, name))

// THEN
msAvn, err := avnClient.Services.Get(ctx, cfg.Project, name)
msAvn, err := avnGen.ServiceGet(ctx, cfg.Project, name)
require.NoError(t, err)
assert.Equal(t, msAvn.Name, ms.GetName())
assert.Equal(t, msAvn.ServiceName, ms.GetName())
assert.Equal(t, serviceRunningState, ms.Status.State)
assert.Contains(t, serviceRunningStatesAiven, msAvn.State)
assert.Equal(t, msAvn.Plan, ms.Spec.Plan)
assert.Equal(t, msAvn.CloudName, ms.Spec.CloudName)
assert.Equal(t, "100GiB", ms.Spec.DiskSpace)
assert.Equal(t, 102400, msAvn.DiskSpaceMB)
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, cfg.Project, name)
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions tests/opensearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ func TestOpenSearch(t *testing.T) {
require.NoError(t, s.GetRunning(os, name))

// THEN
osAvn, err := avnClient.Services.Get(ctx, cfg.Project, name)
osAvn, err := avnGen.ServiceGet(ctx, cfg.Project, name)
require.NoError(t, err)
assert.Equal(t, osAvn.Name, os.GetName())
assert.Equal(t, osAvn.ServiceName, os.GetName())
assert.Equal(t, serviceRunningState, os.Status.State)
assert.Contains(t, serviceRunningStatesAiven, osAvn.State)
assert.Equal(t, osAvn.Plan, os.Spec.Plan)
assert.Equal(t, osAvn.CloudName, os.Spec.CloudName)
assert.Equal(t, "240GiB", os.Spec.DiskSpace)
assert.Equal(t, 245760, osAvn.DiskSpaceMB)
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, cfg.Project, name)
require.NoError(t, err)
Expand Down
21 changes: 10 additions & 11 deletions tests/postgresql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"testing"

"github.com/aiven/aiven-go-client/v2"
"github.com/aiven/go-client-codegen/handler/service"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -92,9 +91,9 @@ func TestPgReadReplica(t *testing.T) {

// THEN
// Validates instances
masterAvn, err := avnClient.Services.Get(ctx, cfg.Project, masterName)
masterAvn, err := avnGen.ServiceGet(ctx, cfg.Project, masterName)
require.NoError(t, err)
assert.Equal(t, masterAvn.Name, master.GetName())
assert.Equal(t, masterAvn.ServiceName, master.GetName())
assert.Equal(t, serviceRunningState, master.Status.State)
assert.Contains(t, serviceRunningStatesAiven, masterAvn.State)
assert.Equal(t, masterAvn.Plan, master.Spec.Plan)
Expand All @@ -106,9 +105,9 @@ func TestPgReadReplica(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, masterResp.Tags, master.Spec.Tags)

replicaAvn, err := avnClient.Services.Get(ctx, cfg.Project, replicaName)
replicaAvn, err := avnGen.ServiceGet(ctx, cfg.Project, replicaName)
require.NoError(t, err)
assert.Equal(t, replicaAvn.Name, replica.GetName())
assert.Equal(t, replicaAvn.ServiceName, replica.GetName())
assert.Equal(t, serviceRunningState, replica.Status.State)
assert.Contains(t, serviceRunningStatesAiven, replicaAvn.State)
assert.Equal(t, replicaAvn.Plan, replica.Spec.Plan)
Expand Down Expand Up @@ -176,7 +175,7 @@ spec:
tags:
env: prod
instance: pg
userConfig:
pg_version: "14"
`, project, pgName, cloudName)
Expand Down Expand Up @@ -207,9 +206,9 @@ func TestPgCustomPrefix(t *testing.T) {

// THEN
// Validates instance
pgAvn, err := avnClient.Services.Get(ctx, cfg.Project, pgName)
pgAvn, err := avnGen.ServiceGet(ctx, cfg.Project, pgName)
require.NoError(t, err)
assert.Equal(t, pgAvn.Name, pg.GetName())
assert.Equal(t, pgAvn.ServiceName, pg.GetName())
assert.Equal(t, serviceRunningState, pg.Status.State)
assert.Contains(t, serviceRunningStatesAiven, pgAvn.State)
assert.Equal(t, pgAvn.Plan, pg.Spec.Plan)
Expand Down Expand Up @@ -294,7 +293,7 @@ func TestPgUpgradeVersion(t *testing.T) {
pg := new(v1alpha1.PostgreSQL)
require.NoError(t, s.GetRunning(pg, pgName))

pgAvn, err := avnClient.Services.Get(ctx, cfg.Project, pgName)
pgAvn, err := avnGen.ServiceGet(ctx, cfg.Project, pgName)
require.NoError(t, err)
assert.Equal(t, startingVersion, pgAvn.UserConfig["pg_version"])
assert.Equal(t, anyPointer(startingVersion), pg.Spec.UserConfig.PgVersion)
Expand All @@ -306,9 +305,9 @@ func TestPgUpgradeVersion(t *testing.T) {
require.NoError(t, s.Apply(updatedYaml))

// Verify that the service was upgraded successfully
var pgAvnUpd *aiven.Service
var pgAvnUpd *service.ServiceGetOut
require.NoError(t, retryForever(ctx, "check that PG version was upgraded", func() (bool, error) {
pgAvnUpd, err = avnClient.Services.Get(ctx, cfg.Project, pgName)
pgAvnUpd, err = avnGen.ServiceGet(ctx, cfg.Project, pgName)
if err != nil {
return false, err
}
Expand Down
12 changes: 6 additions & 6 deletions tests/projectvpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"testing"

"github.com/aiven/aiven-go-client/v2"
"github.com/aiven/go-client-codegen/handler/service"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -126,17 +126,17 @@ func TestProjectVPCID(t *testing.T) {
require.NoError(t, kafkaSession.GetRunning(kafka, kafkaName))

// THEN
kafkaAvn, err := avnClient.Services.Get(ctx, cfg.Project, kafkaName)
kafkaAvn, err := avnGen.ServiceGet(ctx, cfg.Project, kafkaName)
require.NoError(t, err)
assert.Equal(t, kafkaAvn.Name, kafka.GetName())
assert.Equal(t, kafkaAvn.ServiceName, kafka.GetName())
assert.Equal(t, serviceRunningState, kafka.Status.State)
assert.Contains(t, serviceRunningStatesAiven, kafkaAvn.State)
assert.Equal(t, kafkaAvn.Plan, kafka.Spec.Plan)
assert.Equal(t, kafkaAvn.CloudName, kafka.Spec.CloudName)

// Validates VPC
assert.Equal(t, vpc1.Status.ID, kafka.Spec.ProjectVPCID)
assert.Equal(t, anyPointer(vpc1.Status.ID), kafkaAvn.ProjectVPCID)
assert.Equal(t, anyPointer(vpc1.Status.ID), kafkaAvn.ProjectVpcId)

// Migrates the service to vpc2
kafkaYamlUpd := getKafkaForProjectVPCYaml(cfg.Project, vpc2.Status.ID, kafkaName, cfg.TertiaryCloudName)
Expand All @@ -145,9 +145,9 @@ func TestProjectVPCID(t *testing.T) {
// This migration takes too long, so we don't wait it's being in the RUNNING state in kube

// Gets Aiven object
var kafkaAvnUpd *aiven.Service
var kafkaAvnUpd *service.ServiceGetOut
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, cfg.Project, kafkaName)
kafkaAvnUpd, err = avnGen.ServiceGet(ctx, cfg.Project, kafkaName)
if err != nil {
return false, err
}
Expand Down
4 changes: 2 additions & 2 deletions tests/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func TestRedis(t *testing.T) {
require.NoError(t, s.GetRunning(rs, name))

// THEN
rsAvn, err := avnClient.Services.Get(ctx, cfg.Project, name)
rsAvn, err := avnGen.ServiceGet(ctx, cfg.Project, name)
require.NoError(t, err)
assert.Equal(t, rsAvn.Name, rs.GetName())
assert.Equal(t, rsAvn.ServiceName, rs.GetName())
assert.Equal(t, serviceRunningState, rs.Status.State)
assert.Contains(t, serviceRunningStatesAiven, rsAvn.State)
assert.Equal(t, rsAvn.Plan, rs.Spec.Plan)
Expand Down
8 changes: 4 additions & 4 deletions tests/service_opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ func TestServiceTechnicalEmails(t *testing.T) {

// THEN
// Technical emails are set
grafanaAvn, err := avnClient.Services.Get(ctx, cfg.Project, name)
grafanaAvn, err := avnGen.ServiceGet(ctx, cfg.Project, name)
require.NoError(t, err)
assert.Len(t, grafana.Spec.TechnicalEmails, 1)
assert.Equal(t, "[email protected]", grafanaAvn.TechnicalEmails[0].Email)
assert.Equal(t, "[email protected]", grafanaAvn.TechEmails[0].Email)

// WHEN
// Technical emails are removed from manifest
Expand All @@ -78,9 +78,9 @@ func TestServiceTechnicalEmails(t *testing.T) {

// THEN
// Technical emails are removed from service
grafanaAvnUpdated, err := avnClient.Services.Get(ctx, cfg.Project, name)
grafanaAvnUpdated, err := avnGen.ServiceGet(ctx, cfg.Project, name)
require.NoError(t, err)
assert.Empty(t, grafanaAvnUpdated.TechnicalEmails)
assert.Empty(t, grafanaAvnUpdated.TechEmails)
}

func getConnInfoBaseYaml(project, name, cloudName string) string {
Expand Down
Loading

0 comments on commit b654304

Please sign in to comment.