From 5b282917627324078f4473d2d7ffba2ec0351038 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Fri, 11 Oct 2019 10:07:40 -0700 Subject: [PATCH] Clean up tests --- command/fixtures/pr.json | 30 +++++++++++++++++++++++++----- command/pr_test.go | 17 +++++++++++++---- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/command/fixtures/pr.json b/command/fixtures/pr.json index 3d2507c0e..d3a7e89f2 100644 --- a/command/fixtures/pr.json +++ b/command/fixtures/pr.json @@ -5,9 +5,9 @@ { "node": { "number": 10, - "title": "test", + "title": "Blueberries are a good fruit", "url": "https://github.com/github/gh-cli/pull/10", - "headRefName": "test" + "headRefName": "[blueberries]" } } ] @@ -18,13 +18,33 @@ { "node": { "number": 8, - "title": "Pull in the GraphQL API functionality", + "title": "Strawberries are not actually berries", "url": "https://github.com/github/gh-cli/pull/8", - "headRefName": "graphql" + "headRefName": "[strawberries]" } } ], "pageInfo": { "hasNextPage": false } }, - "reviewRequested": { "edges": [], "pageInfo": { "hasNextPage": false } } + "reviewRequested": { + "edges": [ + { + "node": { + "number": 9, + "title": "Apples are tasty", + "url": "https://github.com/github/gh-cli/pull/9", + "headRefName": "[apples]" + } + }, + { + "node": { + "number": 11, + "title": "Figs are my favorite", + "url": "https://github.com/github/gh-cli/pull/1", + "headRefName": "[figs]" + } + } + ], + "pageInfo": { "hasNextPage": false } + } } diff --git a/command/pr_test.go b/command/pr_test.go index 87af934dd..15ba29e50 100644 --- a/command/pr_test.go +++ b/command/pr_test.go @@ -4,13 +4,13 @@ import ( "encoding/json" "io/ioutil" "os" - "strings" + "regexp" "testing" "github.com/github/gh-cli/api" ) -func TestPR(t *testing.T) { +func TestPRList(t *testing.T) { teardown := mockGraphQL("pr.json") defer teardown() @@ -21,8 +21,17 @@ func TestPR(t *testing.T) { } }) - if !strings.Contains(output, "#9 Pull in the GraphQL API functionality [graphql]") { - t.Errorf("expected to list PR #8 but did not") + expectedPrs := []*regexp.Regexp{ + regexp.MustCompile(`#8.*\[strawberries\]`), + regexp.MustCompile(`#9.*\[apples\]`), + regexp.MustCompile(`#10.*\[blueberries\]`), + regexp.MustCompile(`#11.*\[figs\]`), + } + + for _, r := range expectedPrs { + if !r.MatchString(output) { + t.Errorf("output did not match regexp /%s/", r) + } } }