Skip to content

Commit

Permalink
Tests use When instead of Context("When
Browse files Browse the repository at this point in the history
  • Loading branch information
manno committed May 22, 2024
1 parent b0492ca commit b4ce67c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pkg/git/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func newTestGithubServer(refs []string) *httptest.Server {
}

var _ = Describe("git fetch's LatestCommit tests", func() {
Context("When secret credentials does not exist", func() {
When("secret credentials does not exist", func() {
var (
fakeGithub *httptest.Server
refs []string
Expand Down
14 changes: 7 additions & 7 deletions pkg/git/netutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ YcwLYudAztZeA/A4aM5Y0MA6PlNIeoHohuMkSZNOBcvkNEWdzGBpKb34yLfMarNm
})

var _ = Describe("git's GetHTTPClientFromSecret tests", func() {
Context("When using a nil secret, no caBudle and InsecureSkipVerify = false", func() {
When("using a nil secret, no caBudle and InsecureSkipVerify = false", func() {
var caBundle []byte
client, err := git.GetHTTPClientFromSecret(nil, caBundle, false)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -276,7 +276,7 @@ var _ = Describe("git's GetHTTPClientFromSecret tests", func() {
})
})

Context("When using a nil secret, no caBudle and InsecureSkipVerify = true", func() {
When("using a nil secret, no caBudle and InsecureSkipVerify = true", func() {
var caBundle []byte
client, err := git.GetHTTPClientFromSecret(nil, caBundle, true)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -302,7 +302,7 @@ var _ = Describe("git's GetHTTPClientFromSecret tests", func() {
})
})

Context("When using a nil secret, caBudle and InsecureSkipVerify = true", func() {
When("using a nil secret, caBudle and InsecureSkipVerify = true", func() {
caBundlePEM := []byte(`-----BEGIN CERTIFICATE-----
MIICGTCCAZ+gAwIBAgIQCeCTZaz32ci5PhwLBCou8zAKBggqhkjOPQQDAzBOMQsw
CQYDVQQGEwJVUzEXMBUGA1UEChMORGlnaUNlcnQsIEluYy4xJjAkBgNVBAMTHURp
Expand Down Expand Up @@ -344,7 +344,7 @@ DXZDjC5Ty3zfDBeWUA==
})
})

Context("When using a malformed ca bundle", func() {
When("using a malformed ca bundle", func() {
caBundle := []byte(`-----BEGIN CERTIFICATE-----
SUPER FAKE CERT
-----END CERTIFICATE-----`)
Expand All @@ -356,7 +356,7 @@ SUPER FAKE CERT
})
})

Context("When using a valid basic auth secret", func() {
When("using a valid basic auth secret", func() {
username := []byte("superuser")
password := []byte("supersecure")
secret := &corev1.Secret{
Expand All @@ -380,7 +380,7 @@ SUPER FAKE CERT
})
})

Context("When using a valid tls secret", func() {
When("using a valid tls secret", func() {
const certificatePEM = `
-----BEGIN CERTIFICATE-----
MIIBLjCB4aADAgECAhAX0YGTviqMISAQJRXoNCNPMAUGAytlcDASMRAwDgYDVQQK
Expand Down Expand Up @@ -414,7 +414,7 @@ MC4CAQAwBQYDK2VwBCIEINifzf07d9qx3d44e0FSbV4mC/xQxT644RRbpgNpin7I
})
})

Context("When using a non valid tls secret", func() {
When("using a non valid tls secret", func() {
const certificatePEM = `
-----BEGIN CERTIFICATE-----
THIS IS NOT A VALID CERTIFICATE
Expand Down
12 changes: 6 additions & 6 deletions pkg/git/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var _ = Describe("git's RevisionCommit tests", func() {
})
})

Context("When a revision is not found", func() {
When("a revision is not found", func() {
BeforeEach(func() {
fakeLister = &FakeRemoteLister{
RetValues: []*git.RemoteRef{
Expand All @@ -59,7 +59,7 @@ var _ = Describe("git's RevisionCommit tests", func() {
})
})

Context("When the go-git List function fails", func() {
When("the go-git List function fails", func() {
BeforeEach(func() {
fakeLister = &FakeRemoteLister{
RetError: fmt.Errorf("THIS IS A TEST ERROR"),
Expand All @@ -75,7 +75,7 @@ var _ = Describe("git's RevisionCommit tests", func() {
})
})

Context("When the given revision is a lighweight tag", func() {
When("the given revision is a lighweight tag", func() {
var tagCommit = "b2f7eacdeda55833e299efdd6955abb68f581547"
BeforeEach(func() {
fakeLister = &FakeRemoteLister{
Expand All @@ -99,7 +99,7 @@ var _ = Describe("git's RevisionCommit tests", func() {
})
})

Context("When then given revision is an annotated tag", func() {
When("then given revision is an annotated tag", func() {
var tagCommit = "b2f7eacdeda55833e299efdd6955abb68f581547"
BeforeEach(func() {
fakeLister = &FakeRemoteLister{
Expand Down Expand Up @@ -180,7 +180,7 @@ var _ = Describe("git's LatestBranchCommit tests", func() {
})
})

Context("When the go-git List function fails", func() {
When("the go-git List function fails", func() {
BeforeEach(func() {
fakeLister = &FakeRemoteLister{
RetError: fmt.Errorf("THIS IS A TEST ERROR"),
Expand All @@ -195,7 +195,7 @@ var _ = Describe("git's LatestBranchCommit tests", func() {
})
})

Context("When passing a non-valid branch", func() {
When("passing a non-valid branch", func() {
BeforeEach(func() {
fakeLister = &FakeRemoteLister{
RetError: nil,
Expand Down
14 changes: 7 additions & 7 deletions pkg/git/vendor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,42 @@ var _ = Describe("git's vendor specific functions tests", func() {
})
})

Context("When using not parseable url", func() {
When("using not parseable url", func() {
It("returns en empty string", func() {
resPath := getVendorCommitsURL("\n{this-is-not-an-url}\n", "mybranch")
Expect(resPath).To(BeEmpty())
})
})

Context("When using github host and non-valid address", func() {
When("using github host and non-valid address", func() {
It("returns en empty string", func() {
resPath := getVendorCommitsURL("https://github.com/thisisnotok", "mybranch")
Expect(resPath).To(BeEmpty())
})
})

Context("When using github host and valid address", func() {
When("using github host and valid address", func() {
It("returns en empty string", func() {
resPath := getVendorCommitsURL("https://github.com/rancher/fleet", "mybranch")
Expect(resPath).To(Equal("https://api.github.com/repos/rancher/fleet/commits/mybranch"))
})
})

Context("When using rancher host and non-valid address", func() {
When("using rancher host and non-valid address", func() {
It("returns en empty string", func() {
resPath := getVendorCommitsURL("https://git.rancher.io", "mybranch")
Expect(resPath).To(BeEmpty())
})
})

Context("When using rancher host and valid address", func() {
When("using rancher host and valid address", func() {
It("returns en empty string", func() {
resPath := getVendorCommitsURL("https://git.rancher.io/repository", "mybranch")
Expect(resPath).To(Equal("https://git.rancher.io/repos/repository/commits/mybranch"))
})
})

Context("When requesting if lastSha has changed with a valid URL", func() {
When("requesting if lastSha has changed with a valid URL", func() {
It("returns the expected latest commit", func() {
latest := "bdb35e1950b5829c88df134810a0aa9a7da9bc22"
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -103,7 +103,7 @@ SUPER FAKE CERT
})
})

Context("When requesting if lastSha has changed with a non valid URL", func() {
When("requesting if lastSha has changed with a non valid URL", func() {
It("returns true and no error when the url is not parseable", func() {
commit, err := latestCommitFromCommitsURL("httpssss://blahblah blaisnotanurl\n", &options{})
// Returns no error and changed = true so the user is forced to run the List to get results
Expand Down

0 comments on commit b4ce67c

Please sign in to comment.