Skip to content

Commit

Permalink
Remove ginkgo from api tests (#399)
Browse files Browse the repository at this point in the history
This is related to epic #189, although there doesn't seem to be a related
issue for this directory.

Signed-off-by: Todd Short <tshort@redhat.com>
  • Loading branch information
tmshort committed Sep 7, 2023
1 parent 98e3e2e commit 1ec4a23
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 40 deletions.
64 changes: 37 additions & 27 deletions api/v1alpha1/operator_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions api/v1alpha1/v1alpha1_suite_test.go

This file was deleted.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 1ec4a23

Please sign in to comment.