From 95c7de83decd7e22b13ecb6165aa76d0e6c6975f Mon Sep 17 00:00:00 2001 From: Yury Kovalev Date: Wed, 22 May 2024 18:56:34 +0200 Subject: [PATCH] Fix tests --- .../dinosaur/pkg/services/clusters_test.go | 18 +++++++++--------- .../dinosaur/pkg/services/dinosaur_test.go | 17 +++++++++-------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/internal/dinosaur/pkg/services/clusters_test.go b/internal/dinosaur/pkg/services/clusters_test.go index 1eb1267a4a..6fc76397f2 100644 --- a/internal/dinosaur/pkg/services/clusters_test.go +++ b/internal/dinosaur/pkg/services/clusters_test.go @@ -220,8 +220,8 @@ func Test_GetClusterDNS(t *testing.T) { }, } mocket.Catcher.Reset(). - NewMock().WithQuery(`SELECT * FROM "clusters" WHERE "clusters"."cluster_id" = $1`). - WithArgs(testClusterID). + NewMock().WithQuery(`SELECT * FROM "clusters" WHERE "clusters"."cluster_id" = $1 AND "clusters"."deleted_at" IS NULL ORDER BY "clusters"."id" LIMIT $2`). + WithArgs(testClusterID, int64(1)). WithReply(res) }, wantErr: false, @@ -329,8 +329,8 @@ func Test_Cluster_FindClusterByID(t *testing.T) { mockedResponse := []map[string]interface{}{{"cluster_id": testClusterID}} mocket.Catcher.Reset(). NewMock(). - WithQuery(`SELECT * FROM "clusters" WHERE "clusters"."cluster_id" = $1`). - WithArgs(testClusterID). + WithQuery(`SELECT * FROM "clusters" WHERE "clusters"."cluster_id" = $1 AND "clusters"."deleted_at" IS NULL ORDER BY "clusters"."id" LIMIT $2`). + WithArgs(testClusterID, int64(1)). WithReply(mockedResponse) }, }, @@ -956,7 +956,7 @@ func Test_Cluster_FindNonEmptyClusterByID(t *testing.T) { want: &api.Cluster{ClusterID: testClusterID, Meta: api.Meta{CreatedAt: now, UpdatedAt: now, DeletedAt: gorm.DeletedAt{Valid: true}}}, setupFn: func() { mockedResponse := []map[string]interface{}{{"cluster_id": testClusterID, "created_at": now, "updated_at": now, "deleted_at": gorm.DeletedAt{Valid: true}.Time}} - query := `SELECT * FROM "clusters" WHERE "clusters"."cluster_id" = $1 AND cluster_id IN (SELECT "cluster_id" FROM "central_requests" WHERE (status != $2 AND cluster_id = $3) AND "central_requests"."deleted_at" IS NULL) AND "clusters"."deleted_at" IS NULL ORDER BY "clusters"."id" LIMIT 1%` + query := `SELECT * FROM "clusters" WHERE "clusters"."cluster_id" = $1 AND cluster_id IN (SELECT "cluster_id" FROM "central_requests" WHERE (status != $2 AND cluster_id = $3) AND "central_requests"."deleted_at" IS NULL) AND "clusters"."deleted_at" IS NULL ORDER BY "clusters"."id" LIMIT $4%` mocket.Catcher.Reset().NewMock().WithQuery(query).WithReply(mockedResponse) }, }, @@ -1587,8 +1587,8 @@ func Test_ClusterService_GetExternalID(t *testing.T) { mockedResponse := []map[string]interface{}{{"external_id": "test-cluster-id"}} mocket.Catcher.Reset(). NewMock(). - WithQuery(`SELECT * FROM "clusters" WHERE "clusters"."cluster_id" = $1`). - WithArgs(testClusterID). + WithQuery(`SELECT * FROM "clusters" WHERE "clusters"."cluster_id" = $1 AND "clusters"."deleted_at" IS NULL ORDER BY "clusters"."id" LIMIT $2`). + WithArgs(testClusterID, int64(1)). WithReply(mockedResponse) mocket.Catcher.NewMock().WithExecException().WithQueryException() }, @@ -1608,8 +1608,8 @@ func Test_ClusterService_GetExternalID(t *testing.T) { mockedResponse := []map[string]interface{}{{"external_id": ""}} mocket.Catcher.Reset(). NewMock(). - WithQuery(`SELECT * FROM "clusters" WHERE "clusters"."cluster_id" = $1`). - WithArgs(testClusterID). + WithQuery(`SELECT * FROM "clusters" WHERE "clusters"."cluster_id" = $1 AND "clusters"."deleted_at" IS NULL ORDER BY "clusters"."id" LIMIT $2`). + WithArgs(testClusterID, int64(1)). WithReply(mockedResponse) mocket.Catcher.NewMock().WithExecException().WithQueryException() }, diff --git a/internal/dinosaur/pkg/services/dinosaur_test.go b/internal/dinosaur/pkg/services/dinosaur_test.go index 4f3b4b4287..0ac3390c96 100644 --- a/internal/dinosaur/pkg/services/dinosaur_test.go +++ b/internal/dinosaur/pkg/services/dinosaur_test.go @@ -143,8 +143,8 @@ func Test_dinosaurService_Get(t *testing.T) { setupFn: func() { mocket.Catcher.Reset(). NewMock(). - WithQuery(`SELECT * FROM "central_requests" WHERE id = $1 AND owner = $2`). - WithArgs(testID, testUser). + WithQuery(`SELECT * FROM "central_requests" WHERE id = $1 AND owner = $2 AND "central_requests"."deleted_at" IS NULL ORDER BY "central_requests"."id" LIMIT $3`). + WithArgs(testID, testUser, int64(1)). WithReply(converters.ConvertDinosaurRequest(buildCentralRequest(nil))) }, }, @@ -190,8 +190,9 @@ func Test_dinosaurService_DeprovisionExpiredDinosaursQuery(t *testing.T) { m := mocket.Catcher.Reset().NewMock().WithQuery(`UPDATE "central_requests" ` + `SET "deletion_timestamp"=$1,"status"=$2,"updated_at"=$3 WHERE ` + - `(expired_at IS NOT NULL AND expired_at < $4 OR instance_type = $5 AND created_at <= $6) ` + - `AND status NOT IN ($7,$8) AND "central_requests"."deleted_at" IS NULL`). + `(expired_at IS NOT NULL AND expired_at < $4 OR instance_type = $5 AND created_at <= $6 ` + + `AND (expired_at IS NOT NULL AND expired_at < $7 OR instance_type = $8 AND created_at <= $9) ` + + `AND status NOT IN ($10,$11)) AND "central_requests"."deleted_at" IS NULL`). OneTime() svcErr := k.DeprovisionExpiredDinosaurs() @@ -275,10 +276,10 @@ func Test_dinosaurService_ChangeBillingParameters(t *testing.T) { }) catcher := mocket.Catcher.Reset() - m0 := catcher.NewMock().WithQuery(`SELECT * FROM "central_requests" ` + - `WHERE id = $1 AND "central_requests"."deleted_at" IS NULL ` + - `ORDER BY "central_requests"."id" LIMIT 1`). - OneTime().WithArgs(testID). + m0 := catcher.NewMock().WithQuery(`SELECT * FROM "central_requests" `+ + `WHERE id = $1 AND "central_requests"."deleted_at" IS NULL `+ + `ORDER BY "central_requests"."id" LIMIT $2`). + OneTime().WithArgs(testID, int64(1)). WithReply(converters.ConvertDinosaurRequest(central)) m1 := catcher.NewMock().WithQuery(`UPDATE "central_requests" ` + `SET "updated_at"=$1,"deleted_at"=$2,"region"=$3,"cluster_id"=$4,` +