Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix intermittent test failures caused by the TestAggregatePromotionPlan test #24

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 45 additions & 22 deletions internal/pkg/githubapi/promotion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/google/go-github/v62/github"
"github.com/migueleliasweb/go-github-mock/src/mock"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
cfg "github.com/wayfair-incubator/telefonistka/internal/pkg/configuration"
)

Expand Down Expand Up @@ -48,7 +49,7 @@ func generatePromotionPlanMetadataTestHelper(t *testing.T, config *cfg.Config, e
}
}

func generatePromotionPlanTestHelper(t *testing.T, config *cfg.Config, expectedPromotion map[string]PromotionInstance, mockedHTTPClient *http.Client) {
func generatePromotionPlanTestHelper(t *testing.T, config *cfg.Config, mockedHTTPClient *http.Client, expectedPromotions ...map[string]PromotionInstance) {
t.Helper()
ctx := context.Background()
ghClientPair := GhClientPair{v3Client: github.NewClient(mockedHTTPClient)}
Expand All @@ -75,11 +76,17 @@ func generatePromotionPlanTestHelper(t *testing.T, config *cfg.Config, expectedP
t.Fatalf("Failed to generate promotion plan: err=%s", err)
}

if diff := deep.Equal(expectedPromotion, promotionPlan); diff != nil {
for _, l := range diff {
t.Error(l)
expectedPromotionMatched := false
diffs := []string{}
for _, expectedPromotion := range expectedPromotions {
if diff := deep.Equal(expectedPromotion, promotionPlan); diff != nil {
diffs = append(diffs, diff...)
continue
}
expectedPromotionMatched = true
break
}
assert.True(t, expectedPromotionMatched, diffs)
}

func TestGeneratePromotionConditionalPlan(t *testing.T) {
Expand Down Expand Up @@ -161,7 +168,7 @@ func TestGeneratePromotionConditionalPlan(t *testing.T) {
}),
),
)
generatePromotionPlanTestHelper(t, config, expectedPromotion, mockedHTTPClient)
generatePromotionPlanTestHelper(t, config, mockedHTTPClient, expectedPromotion)
}

func TestAggregatePromotionPlan(t *testing.T) {
Expand Down Expand Up @@ -197,17 +204,33 @@ func TestAggregatePromotionPlan(t *testing.T) {
},
}

expectedPromotion := map[string]PromotionInstance{
"dev/[^/]*/>prod/eu-east-1/|prod/eu-west-1/": {
ComputedSyncPaths: map[string]string{
"prod/eu-east-1/componentA": "dev/us-east-5/componentA",
"prod/eu-west-1/componentA": "dev/us-east-5/componentA",
expectedPromotions := []map[string]PromotionInstance{
{
"dev/[^/]*/>prod/eu-east-1/|prod/eu-west-1/": {
ComputedSyncPaths: map[string]string{
"prod/eu-east-1/componentA": "dev/us-east-5/componentA",
"prod/eu-west-1/componentA": "dev/us-east-5/componentA",
},
},
"lab/[^/]*/>prod/us-east-1/|prod/us-west-1/": {
ComputedSyncPaths: map[string]string{
"prod/us-east-1/componentA": "lab/us-east-5/componentA",
"prod/us-west-1/componentA": "lab/us-east-5/componentA",
},
},
},
"lab/[^/]*/>prod/us-east-1/|prod/us-west-1/": {
ComputedSyncPaths: map[string]string{
"prod/us-east-1/componentA": "lab/us-east-5/componentA",
"prod/us-west-1/componentA": "lab/us-east-5/componentA",
{
"dev/[^/]*/>prod/eu-east-1/|prod/eu-west-1/": {
ComputedSyncPaths: map[string]string{
"prod/eu-east-1/componentA": "dev/us-east-4/componentA",
"prod/eu-west-1/componentA": "dev/us-east-4/componentA",
},
},
"lab/[^/]*/>prod/us-east-1/|prod/us-west-1/": {
ComputedSyncPaths: map[string]string{
"prod/us-east-1/componentA": "lab/us-east-5/componentA",
"prod/us-west-1/componentA": "lab/us-east-5/componentA",
},
},
},
}
Expand All @@ -233,7 +256,7 @@ func TestAggregatePromotionPlan(t *testing.T) {
),
)

generatePromotionPlanTestHelper(t, config, expectedPromotion, mockedHTTPClient)
generatePromotionPlanTestHelper(t, config, mockedHTTPClient, expectedPromotions...)
}

func TestGenerateSourceRegexPromotionPlan(t *testing.T) {
Expand Down Expand Up @@ -283,7 +306,7 @@ func TestGenerateSourceRegexPromotionPlan(t *testing.T) {
}),
),
)
generatePromotionPlanTestHelper(t, config, expectedPromotion, mockedHTTPClient)
generatePromotionPlanTestHelper(t, config, mockedHTTPClient, expectedPromotion)
}

func TestGeneratePromotionPlan(t *testing.T) {
Expand Down Expand Up @@ -332,7 +355,7 @@ func TestGeneratePromotionPlan(t *testing.T) {
}),
),
)
generatePromotionPlanTestHelper(t, config, expectedPromotion, mockedHTTPClient)
generatePromotionPlanTestHelper(t, config, mockedHTTPClient, expectedPromotion)
}

func TestGeneratePromotionPlanBlockList(t *testing.T) {
Expand Down Expand Up @@ -376,7 +399,7 @@ func TestGeneratePromotionPlanBlockList(t *testing.T) {
},
),
)
generatePromotionPlanTestHelper(t, config, expectedPromotion, mockedHTTPClient)
generatePromotionPlanTestHelper(t, config, mockedHTTPClient, expectedPromotion)
}

func TestGeneratePromotionPlanAllowList(t *testing.T) {
Expand Down Expand Up @@ -419,7 +442,7 @@ func TestGeneratePromotionPlanAllowList(t *testing.T) {
},
),
)
generatePromotionPlanTestHelper(t, config, expectedPromotion, mockedHTTPClient)
generatePromotionPlanTestHelper(t, config, mockedHTTPClient, expectedPromotion)
}

func TestGeneratePromotionPlanTwoComponents(t *testing.T) {
Expand Down Expand Up @@ -468,7 +491,7 @@ func TestGeneratePromotionPlanTwoComponents(t *testing.T) {
}),
),
)
generatePromotionPlanTestHelper(t, config, expectedPromotion, mockedHTTPClient)
generatePromotionPlanTestHelper(t, config, mockedHTTPClient, expectedPromotion)
}

func TestGenerateNestedSourceRegexPromotionPlan(t *testing.T) {
Expand Down Expand Up @@ -515,7 +538,7 @@ func TestGenerateNestedSourceRegexPromotionPlan(t *testing.T) {
}),
),
)
generatePromotionPlanTestHelper(t, config, expectedPromotion, mockedHTTPClient)
generatePromotionPlanTestHelper(t, config, mockedHTTPClient, expectedPromotion)
}

func TestGeneratePromotionPlanWithPagination(t *testing.T) {
Expand Down Expand Up @@ -567,7 +590,7 @@ func TestGeneratePromotionPlanWithPagination(t *testing.T) {
}),
),
)
generatePromotionPlanTestHelper(t, config, expectedPromotion, mockedHTTPClient)
generatePromotionPlanTestHelper(t, config, mockedHTTPClient, expectedPromotion)
}

// TestGeneratePromotionMetadataWithOutDesc tests the case where the target description is set
Expand Down
Loading