From 1ec4a23ba8ae6000d315ee4da0d01f37f2e2973b Mon Sep 17 00:00:00 2001 From: Todd Short Date: Thu, 7 Sep 2023 10:49:04 -0400 Subject: [PATCH] Remove ginkgo from api tests (#399) This is related to epic #189, although there doesn't seem to be a related issue for this directory. Signed-off-by: Todd Short --- api/v1alpha1/operator_types_test.go | 64 +++++++++++++++++------------ api/v1alpha1/v1alpha1_suite_test.go | 13 ------ go.mod | 1 + go.sum | 2 + 4 files changed, 40 insertions(+), 40 deletions(-) delete mode 100644 api/v1alpha1/v1alpha1_suite_test.go diff --git a/api/v1alpha1/operator_types_test.go b/api/v1alpha1/operator_types_test.go index 5fd7b5182..b63b0acfb 100644 --- a/api/v1alpha1/operator_types_test.go +++ b/api/v1alpha1/operator_types_test.go @@ -8,39 +8,49 @@ import ( "io/fs" "strconv" "strings" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + "testing" "github.com/operator-framework/operator-controller/internal/conditionsets" + + "golang.org/x/exp/slices" // replace with "slices" in go 1.21 ) -var _ = Describe("OperatorTypes", func() { - Describe("Condition Type and Reason constants", func() { - It("should register types in conditionsets.ConditionTypes", func() { - types, err := parseConstants("Type") - Expect(err).NotTo(HaveOccurred()) +func TestOperatorTypeRegistration(t *testing.T) { + types, err := parseConstants("Type") + if err != nil { + t.Fatalf("unable to parse Type constants %v", err) + } - for _, t := range types { - Expect(t).To(BeElementOf(conditionsets.ConditionTypes), "Append Type%s to conditionsets.ConditionTypes in this package's init function.", t) - } - for _, t := range conditionsets.ConditionTypes { - Expect(t).To(BeElementOf(types), "There must be a Type%[1]s string literal constant for type %[1]q (i.e. 'const Type%[1]s = %[1]q')", t) - } - }) - It("should register reasons in conditionsets.ConditionReasons", func() { - reasons, err := parseConstants("Reason") - Expect(err).NotTo(HaveOccurred()) + for _, tt := range types { + if !slices.Contains(conditionsets.ConditionTypes, tt) { + t.Errorf("append Type%s to conditionsets.ConditionTypes in this package's init function", tt) + } + } - for _, r := range reasons { - Expect(r).To(BeElementOf(conditionsets.ConditionReasons), "Append Reason%s to conditionsets.ConditionReasons in this package's init function.", r) - } - for _, r := range conditionsets.ConditionReasons { - Expect(r).To(BeElementOf(reasons), "There must be a Reason%[1]s string literal constant for reason %[1]q (i.e. 'const Reason%[1]s = %[1]q')", r) - } - }) - }) -}) + for _, tt := range conditionsets.ConditionTypes { + if !slices.Contains(types, tt) { + t.Errorf("there must be a Type%[1]s string literal constant for type %[1]q (i.e. 'const Type%[1]s = %[1]q')", tt) + } + } +} + +func TestOperatorReasonRegistration(t *testing.T) { + reasons, err := parseConstants("Reason") + if err != nil { + t.Fatalf("unable to parse Reason constants %v", err) + } + + for _, r := range reasons { + if !slices.Contains(conditionsets.ConditionReasons, r) { + t.Errorf("append Reason%s to conditionsets.ConditionReasons in this package's init function.", r) + } + } + for _, r := range conditionsets.ConditionReasons { + if !slices.Contains(reasons, r) { + t.Errorf("there must be a Reason%[1]s string literal constant for reason %[1]q (i.e. 'const Reason%[1]s = %[1]q')", r) + } + } +} // parseConstants parses the values of the top-level constants in the current // directory whose names start with the given prefix. When running as part of a diff --git a/api/v1alpha1/v1alpha1_suite_test.go b/api/v1alpha1/v1alpha1_suite_test.go deleted file mode 100644 index 761ff0202..000000000 --- a/api/v1alpha1/v1alpha1_suite_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package v1alpha1_test - -import ( - "testing" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -func TestV1alpha1(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "V1alpha1 Suite") -} diff --git a/go.mod b/go.mod index edf5f553d..678b1d4da 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.4 go.uber.org/zap v1.25.0 + golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 k8s.io/apiextensions-apiserver v0.26.1 k8s.io/apimachinery v0.26.1 k8s.io/client-go v0.26.1 diff --git a/go.sum b/go.sum index efc721ba1..6c64f6d22 100644 --- a/go.sum +++ b/go.sum @@ -940,6 +940,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 h1:pVgRXcIictcr+lBQIFeiwuwtDIs4eL21OuM9nyAADmo= +golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=