Skip to content

Commit

Permalink
Test cloner; add missing setDefaults call
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 018e7db commit 87b0468
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 2 deletions.
4 changes: 4 additions & 0 deletions internal/jira/cloner.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ func Clone(issue *github.Issue, opts ...Option) error {
}
}

if err := config.setDefaults(); err != nil {
return err
}

jiraClient, err := gojira.NewClient(config.client, config.jiraURL)
if err != nil {
return err
Expand Down
105 changes: 103 additions & 2 deletions internal/jira/cloner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ package jira
import (
"os"

"github.com/migueleliasweb/go-github-mock/src/mock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("Lister", func() {
var _ = Describe("Cloner", func() {

// Test out the ListerConfig struct and its methods
// Test out the ClonerConfig struct and its methods
Context("ClonerConfig", func() {
Describe("getToken", func() {
var (
Expand Down Expand Up @@ -58,6 +59,106 @@ var _ = Describe("Lister", func() {
})
})

Context("With Option methods", func() {
var (
options ClonerConfig
)
BeforeEach(func() {
options = ClonerConfig{}
})
Describe("WithClient", func() {
It("should set client to nil if passed nil", func() {
opt := WithClient(nil)
err := opt(&options)
Expect(err).NotTo(HaveOccurred())
Expect(options.client).To(BeNil())
})
It("should set the client if given one", func() {
mc := mock.NewMockedHTTPClient()
opt := WithClient(mc)
err := opt(&options)
Expect(err).NotTo(HaveOccurred())
Expect(options.client).To(Equal(mc))
})
})
Describe("WithDryRun", func() {
It("should set the dryrun to false", func() {
opt := WithDryRun(false)
err := opt(&options)
Expect(err).NotTo(HaveOccurred())
Expect(options.dryRun).To(BeFalse())
})
})
Describe("WithProject", func() {
It("should set the project", func() {
opt := WithProject("OSDK")
err := opt(&options)
Expect(err).NotTo(HaveOccurred())
Expect(options.project).To(Equal("OSDK"))
})
})
Describe("WithJiraURL", func() {
It("should set the jira url", func() {
url := "https://issues.jira.com"
opt := WithJiraURL(url)
err := opt(&options)
Expect(err).NotTo(HaveOccurred())
Expect(options.jiraURL).To(Equal(url))
})
})
})

Describe("getWebURL", func() {
It("should convert the Github API URL to web URL", func() {
apiurl := "https://api.github.com/repos/operator-framework/operator-sdk/issues/3447"
expectedurl := "https://github.com/operator-framework/operator-sdk/issues/3447"
Expect(getWebURL(apiurl)).To(Equal(expectedurl))
})
It("should leave url untouched if it is blank", func() {
apiurl := ""
expectedurl := ""
Expect(getWebURL(apiurl)).To(Equal(expectedurl))
})
It("should leave url untouched if it does not have any matching strings", func() {
apiurl := "http://www.google.com"
expectedurl := "http://www.google.com"
Expect(getWebURL(apiurl)).To(Equal(expectedurl))

apiurl = "http://example.com"
expectedurl = "http://example.com"
Expect(getWebURL(apiurl)).To(Equal(expectedurl))

apiurl = "http://github.com/operator-framework"
expectedurl = "http://github.com/operator-framework"
Expect(getWebURL(apiurl)).To(Equal(expectedurl))
})
})

Describe("Clone", func() {
var (
originalToken string
)
BeforeEach(func() {
originalToken = os.Getenv("JIRA_TOKEN")
err := os.Setenv("JIRA_TOKEN", "blah-blah-blah")
Expect(err).NotTo(HaveOccurred())
})
AfterEach(func() {
err := os.Setenv("JIRA_TOKEN", originalToken)
Expect(err).NotTo(HaveOccurred())
})
It("shoud return an error if there is no token", func() {
err := os.Unsetenv("JIRA_TOKEN")
Expect(err).NotTo(HaveOccurred())

err = Clone(nil)
Expect(err).To(HaveOccurred())
})
It("should print out issue when dryRun is true", func() {
})
It("should save issue in jira when dryRun is false", func() {
})
It("should return an error if jira client returns an error", func() {
})
})
})

0 comments on commit 87b0468

Please sign in to comment.