From 323076a8a9f599580747d14a6748c7255edb72ba 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 114b6b7628029..2d6eba7b590a1 100644 --- a/lib/web/integrations_awsoidc.go +++ b/lib/web/integrations_awsoidc.go @@ -827,7 +827,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. fetchedDbSvcs, err := fetchAWSOIDCDatabaseServices(ctx, clt) if err != nil { diff --git a/lib/web/integrations_awsoidc_test.go b/lib/web/integrations_awsoidc_test.go index b9655c8268aea..bfa91cc4cbed1 100644 --- a/lib/web/integrations_awsoidc_test.go +++ b/lib/web/integrations_awsoidc_test.go @@ -963,8 +963,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", @@ -983,13 +981,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",