Skip to content

Commit

Permalink
Increase coverage in the openshift package
Browse files Browse the repository at this point in the history
Adds a couple of small cases for GetOpenshiftClusterVersion. Will need
refactoring to get further coverage.

Adds cases to the Openshift client tests, where the item already
exists.

Signed-off-by: Brad P. Crochet <brad@redhat.com>
  • Loading branch information
bcrochet committed Jun 30, 2022
1 parent 3c45eb7 commit c0719d2
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
64 changes: 63 additions & 1 deletion certification/internal/openshift/openshift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ var _ = Describe("OpenShift Engine", func() {
Expect(err).ToNot(HaveOccurred())
Expect(ns).ToNot(BeNil())
})
By("creating it again should error", func() {
ns, err := oc.CreateNamespace(context.TODO(), "testns")
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(ErrAlreadyExists))
Expect(ns).ToNot(BeNil())
})
By("getting that Namespace", func() {
ns, err := oc.GetNamespace(context.TODO(), "testns")
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -135,6 +141,12 @@ var _ = Describe("OpenShift Engine", func() {
Expect(err).ToNot(HaveOccurred())
Expect(og).ToNot(BeNil())
})
By("creating it again should error", func() {
og, err := oc.CreateOperatorGroup(context.TODO(), operatorGroupData, "testns")
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(ErrAlreadyExists))
Expect(og).ToNot(BeNil())
})
By("getting that OperatorGroup", func() {
og, err := oc.GetOperatorGroup(context.TODO(), "testog", "testns")
Expect(err).ToNot(HaveOccurred())
Expand All @@ -161,6 +173,14 @@ var _ = Describe("OpenShift Engine", func() {
Expect(err).ToNot(HaveOccurred())
Expect(secret).ToNot(BeNil())
})
By("creating a Secret again should error", func() {
content := make(map[string]string, 1)
content["test"] = "testdata"
secret, err := oc.CreateSecret(context.TODO(), "testsecret", content, corev1.SecretTypeDockerConfigJson, "testns")
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(ErrAlreadyExists))
Expect(secret).ToNot(BeNil())
})
By("getting that Secret", func() {
secret, err := oc.GetSecret(context.TODO(), "testsecret", "testns")
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -193,6 +213,17 @@ var _ = Describe("OpenShift Engine", func() {
Expect(err).ToNot(HaveOccurred())
Expect(cs).ToNot(BeNil())
})
By("creating a CatalogSource again should error", func() {
csData := CatalogSourceData{
Name: "testcs",
Image: "this/is/my-image:now",
Secrets: []string{"my-secrets"},
}
cs, err := oc.CreateCatalogSource(context.TODO(), csData, "testns")
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(ErrAlreadyExists))
Expect(cs).ToNot(BeNil())
})
By("getting that CatalogSource", func() {
cs, err := oc.GetCatalogSource(context.TODO(), "testcs", "testns")
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -224,6 +255,19 @@ var _ = Describe("OpenShift Engine", func() {
Expect(err).ToNot(HaveOccurred())
Expect(sub).ToNot(BeNil())
})
By("creating a Subscription again should error", func() {
subData := SubscriptionData{
Name: "testsub",
Channel: "testchannel",
CatalogSource: "testcs",
CatalogSourceNamespace: "testns",
Package: "testpackage",
}
sub, err := oc.CreateSubscription(context.TODO(), subData, "testns")
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(ErrAlreadyExists))
Expect(sub).ToNot(BeNil())
})
By("getting that Subscription", func() {
sub, err := oc.GetSubscription(context.TODO(), "testsub", "testns")
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -254,6 +298,18 @@ var _ = Describe("OpenShift Engine", func() {
Expect(err).ToNot(HaveOccurred())
Expect(rb).ToNot(BeNil())
})
By("creating a RoleBinding again should error", func() {
rbData := RoleBindingData{
Name: "testrb",
Subjects: []string{"testsubject"},
Role: "testrole",
Namespace: "testns",
}
rb, err := oc.CreateRoleBinding(context.TODO(), rbData, "testns")
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(ErrAlreadyExists))
Expect(rb).ToNot(BeNil())
})
By("getting that RoleBinding", func() {
rb, err := oc.GetRoleBinding(context.TODO(), "testrb", "testns")
Expect(err).ToNot(HaveOccurred())
Expand All @@ -279,10 +335,16 @@ var _ = Describe("OpenShift Engine", func() {
})
})
Context("CSVs", func() {
It("should exercise GetCSV", func() {
It("should get a CSV", func() {
csv, err := oc.GetCSV(context.TODO(), "testcsv", "testns")
Expect(err).ToNot(HaveOccurred())
Expect(csv).ToNot(BeNil())
})
It("should error if CSV doesn't exist", func() {
csv, err := oc.GetCSV(context.TODO(), "badcsv", "badns")
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError(ErrNotFound))
Expect(csv).To(BeNil())
})
})
})
31 changes: 31 additions & 0 deletions certification/internal/openshift/openshift_version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package openshift

import (
"os"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/redhat-openshift-ecosystem/openshift-preflight/certification/runtime"
)

var _ = Describe("OpenShift Version", func() {
When("no KUBECONFIG is provided", func() {
It("should return UnknownVersion and an error", func() {
version, err := GetOpenshiftClusterVersion()
Expect(version).To(BeEquivalentTo(runtime.UnknownOpenshiftClusterVersion()))
Expect(err).To(HaveOccurred())
})
})

When("an invalid KUBECONFIG is passed", func() {
BeforeEach(func() {
os.Setenv("KUBECONFIG", "/bad/kubeconfig")
DeferCleanup(os.Unsetenv, "KUBECONFIG")
})
It("should return UnkownVersion and an error", func() {
version, err := GetOpenshiftClusterVersion()
Expect(version).To(BeEquivalentTo(runtime.UnknownOpenshiftClusterVersion()))
Expect(err).To(HaveOccurred())
})
})
})

0 comments on commit c0719d2

Please sign in to comment.