Skip to content

Commit

Permalink
Enhance integration-test
Browse files Browse the repository at this point in the history
We updated the Build predicates and watcher
We added test cases to verify that validations on
the Build are taking place when a particular annotation is defined
on a secret.

Modify build controller watches secrets integration tests

Signed-off-by: Zoe <[email protected]>
  • Loading branch information
qu1queee committed Dec 7, 2020
1 parent bf3cabd commit 4b5759d
Show file tree
Hide file tree
Showing 6 changed files with 744 additions and 15 deletions.
17 changes: 5 additions & 12 deletions pkg/controller/build/build_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ var _ = Describe("Reconcile Build", func() {
statusWriter.UpdateCalls(statusCall)

_, err := reconciler.Reconcile(request)
Expect(err).To(HaveOccurred())
Expect(err).To(BeNil())
Expect(statusWriter.UpdateCallCount()).To(Equal(1))
Expect(err.Error()).To(ContainSubstring("secret non-existing does not exist"))
})

It("succeeds when the secret exists", func() {
Expand Down Expand Up @@ -166,9 +165,8 @@ var _ = Describe("Reconcile Build", func() {
statusWriter.UpdateCalls(statusCall)

_, err := reconciler.Reconcile(request)
Expect(err).To(HaveOccurred())
Expect(err).To(BeNil())
Expect(statusWriter.UpdateCallCount()).To(Equal(1))
Expect(err.Error()).To(ContainSubstring("secret non-existing does not exist"))
})

It("succeeds when the secret exists", func() {
Expand Down Expand Up @@ -225,9 +223,8 @@ var _ = Describe("Reconcile Build", func() {
statusWriter.UpdateCalls(statusCall)

_, err := reconciler.Reconcile(request)
Expect(err).To(HaveOccurred())
Expect(err).To(BeNil())
Expect(statusWriter.UpdateCallCount()).To(Equal(1))
Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("secret %s does not exist", registrySecret)))
})
It("succeed when the secret exists", func() {

Expand Down Expand Up @@ -270,9 +267,8 @@ var _ = Describe("Reconcile Build", func() {
statusWriter.UpdateCalls(statusCall)

_, err := reconciler.Reconcile(request)
Expect(err).To(HaveOccurred())
Expect(err).To(BeNil())
Expect(statusWriter.UpdateCallCount()).To(Equal(1))
Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("there are no secrets in namespace %s", namespace)))
})
})

Expand Down Expand Up @@ -300,11 +296,8 @@ var _ = Describe("Reconcile Build", func() {
})

_, err := reconciler.Reconcile(request)
Expect(err).To(HaveOccurred())
Expect(err).To(BeNil())
Expect(statusWriter.UpdateCallCount()).To(Equal(1))
Expect(err.Error()).To(ContainSubstring("do not exist"))
Expect(err.Error()).To(ContainSubstring("non-existing-source"))
Expect(err.Error()).To(ContainSubstring("non-existing-output"))
})
})

Expand Down
74 changes: 74 additions & 0 deletions test/build_samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,80 @@ spec:
name: fake-secret
`

// BuildWithOutputRefSecret defines a Build with a
// referenced secret under spec.output
const BuildWithOutputRefSecret = `
apiVersion: build.dev/v1alpha1
kind: Build
spec:
source:
url: "https://github.com/sbose78/taxi"
strategy:
kind: ClusterBuildStrategy
output:
image: image-registry.openshift-image-registry.svc:5000/example/buildpacks-app
credentials:
name: output-secret
timeout: 5s
`

// BuildWithSourceRefSecret defines a Build with a
// referenced secret under spec.source
const BuildWithSourceRefSecret = `
apiVersion: build.dev/v1alpha1
kind: Build
spec:
source:
url: "https://github.com/sbose78/taxi"
credentials:
name: source-secret
strategy:
kind: ClusterBuildStrategy
output:
image: image-registry.openshift-image-registry.svc:5000/example/buildpacks-app
timeout: 5s
`

// BuildWithBuilderRefSecret defines a Build with a
// referenced secret under spec.builder
const BuildWithBuilderRefSecret = `
apiVersion: build.dev/v1alpha1
kind: Build
spec:
source:
url: "https://github.com/sbose78/taxi"
builder:
image: heroku/buildpacks:18
credentials:
name: builder-secret
strategy:
kind: ClusterBuildStrategy
output:
image: image-registry.openshift-image-registry.svc:5000/example/buildpacks-app
timeout: 5s
`

// BuildWithMultipleRefSecrets defines a Build with
// multiple referenced secrets under spec
const BuildWithMultipleRefSecrets = `
apiVersion: build.dev/v1alpha1
kind: Build
spec:
source:
url: "https://github.com/sbose78/taxi"
credentials:
name: source-secret
builder:
image: heroku/buildpacks:18
credentials:
name: builder-secret
strategy:
kind: ClusterBuildStrategy
output:
image: image-registry.openshift-image-registry.svc:5000/example/buildpacks-app
timeout: 5s
`

// BuildCBSWithShortTimeOut defines a Build with a
// ClusterBuildStrategy and a short timeout
const BuildCBSWithShortTimeOut = `
Expand Down
23 changes: 22 additions & 1 deletion test/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ import (
// Catalog allows you to access helper functions
type Catalog struct{}

// SecretWithAnnotation gives you a secret with build annotation
func (c *Catalog) SecretWithAnnotation(name string, ns string) *corev1.Secret {
return &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: ns,
Annotations: map[string]string{build.AnnotationBuildRefSecret: "true"},
},
}
}

// SecretWithoutAnnotation gives you a secret without build annotation
func (c *Catalog) SecretWithoutAnnotation(name string, ns string) *corev1.Secret {
return &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: ns,
},
}
}

// BuildWithClusterBuildStrategy gives you an specific Build CRD
func (c *Catalog) BuildWithClusterBuildStrategy(name string, ns string, strategyName string, secretName string) *build.Build {
buildStrategy := build.ClusterBuildStrategyKind
Expand Down Expand Up @@ -176,7 +197,7 @@ func (c *Catalog) FakeSecretList() corev1.SecretList {
}
}

// FakeSecretListInNamespace to support test
// FakeNoSecretListInNamespace returns an empty secret list
func (c *Catalog) FakeNoSecretListInNamespace() corev1.SecretList {
return corev1.SecretList{
Items: []corev1.Secret{},
Expand Down
Loading

0 comments on commit 4b5759d

Please sign in to comment.