From e7174a4308de1e92b48f5a5ec695aecf0bd29c7d Mon Sep 17 00:00:00 2001 From: Quentin Barrand Date: Fri, 6 Oct 2023 12:36:43 +0200 Subject: [PATCH] Fix a flaky unit test Sometimes a killed process will not write "signal: killed". Handle that case. --- internal/github/issue_test.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/github/issue_test.go b/internal/github/issue_test.go index 4ed694e..a0bfec7 100644 --- a/internal/github/issue_test.go +++ b/internal/github/issue_test.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "errors" + "fmt" "net/http" "os/exec" "testing" @@ -82,7 +83,7 @@ func TestIssueHelper_Create(t *testing.T) { }) t.Run("process error", func(t *testing.T) { - const expectedBody = "gitstream tried to cherry-pick commit `e3229f3c533ed51070beff092e5c7694a8ee81f0` from `some-upstream-url` but was unable to do so.\n" + + const bodyFmt = "gitstream tried to cherry-pick commit `e3229f3c533ed51070beff092e5c7694a8ee81f0` from `some-upstream-url` but was unable to do so.\n" + "\n" + "Commit message:\n" + "```\n" + @@ -93,7 +94,7 @@ func TestIssueHelper_Create(t *testing.T) { "---\n\n" + "**Error**:\n" + "```\n" + - "signal: killed\n" + + "%s\n" + "```\n" + "---\n\n" + "**Command**: `some-command`\n\n" + @@ -105,6 +106,11 @@ func TestIssueHelper_Create(t *testing.T) { "---\n\n" + "Other-Markup: e3229f3c533ed51070beff092e5c7694a8ee81f0" + bodies := []string{ + fmt.Sprintf(bodyFmt, "signal: killed"), + fmt.Sprintf(bodyFmt, ""), + } + c := mock.NewMockedHTTPClient( mock.WithRequestMatchHandler( mock.PostReposIssuesByOwnerByRepo, @@ -116,7 +122,7 @@ func TestIssueHelper_Create(t *testing.T) { json.NewDecoder(r.Body).Decode(&m), ) - assert.Equal(t, expectedBody, m["body"]) + assert.Contains(t, bodies, m["body"]) assert.Equal(t, expectedTitle, m["title"]) assert.Contains(t, m["labels"], "gitstream")