Skip to content

Commit

Permalink
fix(tests): assert destroy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
byashimov committed Jul 10, 2024
1 parent aa12ace commit f2f2d0b
Show file tree
Hide file tree
Showing 27 changed files with 42 additions and 40 deletions.
2 changes: 1 addition & 1 deletion controllers/clickhousegrant_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/clickhouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/clickhousegrant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/clickhouseuser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/connectionpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/generic_service_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/grafana_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/kafka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/kafka_with_projectvpc_ref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/kafkaacl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/kafkaconnect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/kafkaschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/kafkatopic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/kafkschemaregistryaacl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/opensearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/postgresql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion tests/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/projectvpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/service_opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/serviceintegration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/serviceintegrationendpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/serviceuser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions tests/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}

Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down

0 comments on commit f2f2d0b

Please sign in to comment.