Skip to content

Commit

Permalink
Test GetIssue
Browse files Browse the repository at this point in the history
Signed-off-by: jesus m. rodriguez <[email protected]>
  • Loading branch information
jmrodri committed Sep 28, 2022
1 parent 75634e3 commit 018e7db
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions internal/gh/lister_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,50 @@ var _ = Describe("Lister", func() {
Expect(err.Error()).To(Equal("do you see me"))
})
})
Describe("GetIssue", func() {
var (
originalToken string
)
BeforeEach(func() {
originalToken = os.Getenv("GITHUB_TOKEN")
err := os.Setenv("GITHUB_TOKEN", "blah-blah-blah")
Expect(err).NotTo(HaveOccurred())
})
AfterEach(func() {
err := os.Setenv("GITHUB_TOKEN", originalToken)
Expect(err).NotTo(HaveOccurred())
})
It("should return an error if there is no token", func() {
err := os.Unsetenv("GITHUB_TOKEN")
Expect(err).NotTo(HaveOccurred())

iss, err := GetIssue(10)
Expect(iss).To(BeNil())
Expect(err).To(HaveOccurred())
})
It("should return error if Options return an error", func() {
_, err := GetIssue(10, func(c *ListerConfig) error {
return fmt.Errorf("do you see me")
})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("do you see me"))
})
It("should find the open issue", func() {
mockedHTTPClient := mock.NewMockedHTTPClient(
mock.WithRequestMatch(mock.GetReposIssuesByOwnerByRepoByIssueNumber,
github.Issue{
ID: github.Int64(456),
Title: github.String("Issue 2"),
State: github.String("open"),
Number: github.Int(456),
},
),
)
iss, err := GetIssue(456, WithClient(mockedHTTPClient),
WithProject("fakeorg/fakeproject"))
Expect(iss).NotTo(BeNil())
Expect(iss.GetNumber()).To(Equal(456))
Expect(err).NotTo(HaveOccurred())
})
})
})

0 comments on commit 018e7db

Please sign in to comment.