Rearrange the protocol x implementation tests

There is a core chuck of testing that is repeated for {SSH,HTTP} x
{go-git,libgit2}, which is done by repeating a func value in different
contexts. Instead of mutating variables in the func's closure, it's a
bit clearer (and shorter) to pass them to a higher-order func.

Signed-off-by: Michael Bridgen <michael@weave.works>
This commit is contained in:
Michael Bridgen 2021-03-01 19:09:37 +00:00
parent 9c375c582d
commit 8daa6491a3
1 changed files with 219 additions and 238 deletions

View File

@ -111,15 +111,8 @@ var _ = Describe("ImageUpdateAutomation", func() {
Expect(initGitRepo(gitServer, "testdata/appconfig", branch, repositoryPath)).To(Succeed())
})
// These are used for end-to-end tests; withImagePolicy is
// effectively parameterised on these two values.
var (
// set the proto and impl in BeforeEach
proto string
impl string
)
withImagePolicy := func() {
endToEnd := func(impl, proto string) func() {
return func() {
var (
// for cloning locally
cloneLocalRepoURL string
@ -357,35 +350,23 @@ var _ = Describe("ImageUpdateAutomation", func() {
})
})
}
}
Context("Using go-git", func() {
BeforeEach(func() { impl = sourcev1.GoGitImplementation })
Context("with HTTP", func() {
BeforeEach(func() { proto = "http" })
Describe("with image policy", withImagePolicy)
Describe("runs end to end", endToEnd(sourcev1.GoGitImplementation, "http"))
})
Context("with SSH", func() {
BeforeEach(func() { proto = "ssh" })
Describe("with image policy", withImagePolicy)
Describe("runs end to end", endToEnd(sourcev1.GoGitImplementation, "ssh"))
})
})
Context("Using libgit2", func() {
BeforeEach(func() { impl = sourcev1.LibGit2Implementation })
Context("with HTTP", func() {
BeforeEach(func() { proto = "http" })
Describe("with image policy", withImagePolicy)
Describe("runs end to end", endToEnd(sourcev1.LibGit2Implementation, "http"))
})
// Marked "Pending" because the libgit2 SSH implementation
// won't work with the gittestserver yet -- see
// https://github.com/fluxcd/source-controller/issues/287
Context("with SSH", func() {
BeforeEach(func() { proto = "ssh" })
Describe("with image policy", withImagePolicy)
Describe("runs end to end", endToEnd(sourcev1.LibGit2Implementation, "ssh"))
})
})