From 8810e61a52dd392e2b3f7854bd85b42aea75b922 Mon Sep 17 00:00:00 2001 From: Marco Dinis Date: Thu, 9 Jan 2025 17:53:23 +0000 Subject: [PATCH] Deflake TestAWSOIDCRequiredVPCSHelper_CombinedSubnetsForAVpcID Instead of creating an entire cluster, just mock the client to return 0 database services (we were not creating any in the cluster anyway) --- lib/web/integrations_awsoidc.go | 2 +- lib/web/integrations_awsoidc_test.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/web/integrations_awsoidc.go b/lib/web/integrations_awsoidc.go index ca4983354517f..9b58ac5aadf7f 100644 --- a/lib/web/integrations_awsoidc.go +++ b/lib/web/integrations_awsoidc.go @@ -759,7 +759,7 @@ func awsOIDCListAllDatabases(ctx context.Context, clt authclient.ClientI, integr return fetchedRDSs, nil } -func awsOIDCRequiredVPCSHelper(ctx context.Context, clt authclient.ClientI, req ui.AWSOIDCRequiredVPCSRequest, fetchedRDSs []*types.DatabaseV3) (*ui.AWSOIDCRequiredVPCSResponse, error) { +func awsOIDCRequiredVPCSHelper(ctx context.Context, clt client.GetResourcesClient, req ui.AWSOIDCRequiredVPCSRequest, fetchedRDSs []*types.DatabaseV3) (*ui.AWSOIDCRequiredVPCSResponse, error) { // Get all database services with ecs/fargate metadata label. nextToken := "" fetchedDbSvcs := []types.DatabaseService{} diff --git a/lib/web/integrations_awsoidc_test.go b/lib/web/integrations_awsoidc_test.go index ab8a45d36ec6e..ce5631cc32cf2 100644 --- a/lib/web/integrations_awsoidc_test.go +++ b/lib/web/integrations_awsoidc_test.go @@ -882,8 +882,6 @@ func TestAWSOIDCRequiredVPCSHelper(t *testing.T) { func TestAWSOIDCRequiredVPCSHelper_CombinedSubnetsForAVpcID(t *testing.T) { t.Parallel() ctx := context.Background() - env := newWebPack(t, 1) - clt := env.proxies[0].client rdsVPC1 := mustCreateRDS(t, types.RDS{ VPCID: "vpc-1", @@ -902,13 +900,20 @@ func TestAWSOIDCRequiredVPCSHelper_CombinedSubnetsForAVpcID(t *testing.T) { rdss := []*types.DatabaseV3{rdsVPC1, rdsVPC1a, rdsVPC2} - resp, err := awsOIDCRequiredVPCSHelper(ctx, clt, ui.AWSOIDCRequiredVPCSRequest{Region: "us-east-1"}, rdss) + resp, err := awsOIDCRequiredVPCSHelper(ctx, &mockGetResources{}, ui.AWSOIDCRequiredVPCSRequest{Region: "us-east-1"}, rdss) require.NoError(t, err) require.Len(t, resp.VPCMapOfSubnets, 2) require.ElementsMatch(t, []string{"subnet1", "subnet2", "subnet3", "subnet4"}, resp.VPCMapOfSubnets["vpc-1"]) require.ElementsMatch(t, []string{"subnet8"}, resp.VPCMapOfSubnets["vpc-2"]) } +type mockGetResources struct { +} + +func (m *mockGetResources) GetResources(ctx context.Context, req *proto.ListResourcesRequest) (*proto.ListResourcesResponse, error) { + return &proto.ListResourcesResponse{}, nil +} + func mustCreateRDS(t *testing.T, awsRDS types.RDS) *types.DatabaseV3 { rdsDB, err := types.NewDatabaseV3(types.Metadata{ Name: "x",