Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kovayur committed May 23, 2024
1 parent 255a657 commit 95c7de8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
18 changes: 9 additions & 9 deletions internal/dinosaur/pkg/services/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
},
},
Expand Down Expand Up @@ -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)
},
},
Expand Down Expand Up @@ -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()
},
Expand All @@ -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()
},
Expand Down
17 changes: 9 additions & 8 deletions internal/dinosaur/pkg/services/dinosaur_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
},
},
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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,` +
Expand Down

0 comments on commit 95c7de8

Please sign in to comment.