Skip to content

Commit

Permalink
Merge pull request #104 from qbarrand/fix-flaky-test
Browse files Browse the repository at this point in the history
Fix a flaky unit test
  • Loading branch information
qbarrand authored Oct 6, 2023
2 parents 6a78cc0 + e7174a4 commit e8f7b72
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions internal/github/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"os/exec"
"testing"
Expand Down Expand Up @@ -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" +
Expand All @@ -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" +
Expand All @@ -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, "<nil>"),
}

c := mock.NewMockedHTTPClient(
mock.WithRequestMatchHandler(
mock.PostReposIssuesByOwnerByRepo,
Expand All @@ -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")

Expand Down

0 comments on commit e8f7b72

Please sign in to comment.