From 7e218cbc70d7f1baa148938055e854cb510ecded Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Mon, 16 Sep 2024 09:38:57 -0400 Subject: [PATCH] Add test on getOpenStackReleaseVersion --- Makefile | 2 +- apis/core/v1beta1/version_test.go | 40 +++++++++++++++++++++++++ apis/core/v1beta1/webhook_suite_test.go | 7 +++-- 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 apis/core/v1beta1/version_test.go diff --git a/Makefile b/Makefile index b596d9e28..83b943ed9 100644 --- a/Makefile +++ b/Makefile @@ -260,7 +260,7 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen ENVTEST ?= $(LOCALBIN)/setup-envtest CRD_MARKDOWN ?= $(LOCALBIN)/crd-to-markdown GINKGO ?= $(LOCALBIN)/ginkgo -GINKGO_TESTS ?= ./tests/... ./apis/client/... +GINKGO_TESTS ?= ./tests/... ./apis/client/... ./apis/core/... ./apis/dataplane/... KUTTL ?= $(LOCALBIN)/kubectl-kuttl diff --git a/apis/core/v1beta1/version_test.go b/apis/core/v1beta1/version_test.go new file mode 100644 index 000000000..14e5be482 --- /dev/null +++ b/apis/core/v1beta1/version_test.go @@ -0,0 +1,40 @@ +package v1beta1 + +import ( + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +var _ = Describe("OpenStackReleaseVersion", func() { + + Context("test interal getOpenStackReleaseVersion", func() { + + // NOTE: this is the default behavior where OPENSTACK_RELEASE_VERSION is just an environment variable + // and enables the clearest understanding of the version number with regards to testing upgrades + It("Generates a default version based on the OPENSTACK_RELEASE_VERSION when no mode is set", func() { + Expect( + getOpenStackReleaseVersion("1.2.3", "", "openstack-operator.v1.0.0-0.1724144685.p"), + ).To(Equal("1.2.3")) + + }) + + It("Generates a default version based on the OPENSTACK_RELEASE_VERSION when invalid mode is set", func() { + Expect( + getOpenStackReleaseVersion("1.2.3", "asdf", "openstack-operator.v1.0.0-0.1724144685.p"), + ).To(Equal("1.2.3")) + + }) + + // NOTE: this is what some downstream projects use for custom release automation + // Will envolve extra understanding of the version number when testing upgrades with regards to how the + // epoch gets appended + It("Generates a version which appends the epoch when csvEpochAppend is enabled", func() { + Expect( + getOpenStackReleaseVersion("1.2.3", "csvEpochAppend", "openstack-operator.v1.0.0-0.1234567890.p"), + ).To(Equal("1.2.3.1234567890.p")) + + }) + + }) + +}) diff --git a/apis/core/v1beta1/webhook_suite_test.go b/apis/core/v1beta1/webhook_suite_test.go index ce95def86..fd2fb76ba 100644 --- a/apis/core/v1beta1/webhook_suite_test.go +++ b/apis/core/v1beta1/webhook_suite_test.go @@ -18,10 +18,11 @@ package v1beta1 import ( "testing" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" ) -// These tests use Ginkgo (BDD-style Go testing framework). Refer to -// http://onsi.github.io/ginkgo/ to learn more about Ginkgo. -// Implement later func TestAPIs(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Controller v1beta1 Suite") }