Skip to content

Commit

Permalink
Deflake TestAWSOIDCRequiredVPCSHelper_CombinedSubnetsForAVpcID (#50939)
Browse files Browse the repository at this point in the history
Instead of creating an entire cluster, just mock the client to return 0
database services (we were not creating any in the cluster anyway)
  • Loading branch information
marcoandredinis authored Jan 10, 2025
1 parent cca5711 commit a092eaa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/web/integrations_awsoidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,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 {
Expand Down
11 changes: 8 additions & 3 deletions lib/web/integrations_awsoidc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -973,8 +973,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",
Expand All @@ -993,13 +991,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",
Expand Down

0 comments on commit a092eaa

Please sign in to comment.