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 flaky test TestCommitStatusTargetURL #39

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions internal/pkg/githubapi/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,9 @@ func SetCommitStatus(ghPrClientDetails GhPrClientDetails, state string) {
tcontext := "telefonistka"
avatarURL := "https://avatars.githubusercontent.com/u/1616153?s=64"
description := "Telefonistka GitOps Bot"
targetURL := commitStatusTargetURL(time.Now())
tmplFile := os.Getenv("CUSTOM_COMMIT_STATUS_URL_TEMPLATE_PATH")

targetURL := commitStatusTargetURL(time.Now(), tmplFile)

commitStatus := &github.RepoStatus{
TargetURL: &targetURL,
Expand Down Expand Up @@ -1273,10 +1275,9 @@ func GetFileContent(ghPrClientDetails GhPrClientDetails, branch string, filePath
// If the template file is not found or an error occurs during template execution,
// it returns a default URL.
// passed parameter commitTime can be used in the template as .CommitTime
func commitStatusTargetURL(commitTime time.Time) string {
func commitStatusTargetURL(commitTime time.Time, tmplFile string) string {
const targetURL string = "https://github.com/wayfair-incubator/telefonistka"

tmplFile := os.Getenv("CUSTOM_COMMIT_STATUS_URL_TEMPLATE_PATH")
tmplName := filepath.Base(tmplFile)

// dynamic parameters to be used in the template
Expand Down
5 changes: 1 addition & 4 deletions internal/pkg/githubapi/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,12 @@ func TestCommitStatusTargetURL(t *testing.T) {

expectedURL := tc.expectedURL
if tc.templateFile != "" {
os.Setenv("CUSTOM_COMMIT_STATUS_URL_TEMPLATE_PATH", tc.templateFile)
defer os.Unsetenv("CUSTOM_COMMIT_STATUS_URL_TEMPLATE_PATH")

if tc.validTemplate {
expectedURL = fmt.Sprintf(expectedURL, now.UnixMilli(), now.Add(-10*time.Minute).UnixMilli())
}
}

result := commitStatusTargetURL(now)
result := commitStatusTargetURL(now, tc.templateFile)
if result != expectedURL {
t.Errorf("%s: Expected URL to be %q, got %q", name, expectedURL, result)
}
Expand Down
Loading