@@ -8,39 +8,49 @@ import (
88 "io/fs"
99 "strconv"
1010 "strings"
11-
12- . "github.com/onsi/ginkgo/v2"
13- . "github.com/onsi/gomega"
11+ "testing"
1412
1513 "github.com/operator-framework/operator-controller/internal/conditionsets"
14+
15+ "golang.org/x/exp/slices" // replace with "slices" in go 1.21
1616)
1717
18- var _ = Describe ( "OperatorTypes" , func ( ) {
19- Describe ( "Condition Type and Reason constants" , func () {
20- It ( "should register types in conditionsets.ConditionTypes" , func () {
21- types , err := parseConstants ( " Type" )
22- Expect ( err ). NotTo ( HaveOccurred ())
18+ func TestOperatorTypeRegistration ( t * testing. T ) {
19+ types , err := parseConstants ( "Type" )
20+ if err != nil {
21+ t . Fatalf ( "unable to parse Type constants %v" , err )
22+ }
2323
24- for _ , t := range types {
25- Expect (t ).To (BeElementOf (conditionsets .ConditionTypes ), "Append Type%s to conditionsets.ConditionTypes in this package's init function." , t )
26- }
27- for _ , t := range conditionsets .ConditionTypes {
28- 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 )
29- }
30- })
31- It ("should register reasons in conditionsets.ConditionReasons" , func () {
32- reasons , err := parseConstants ("Reason" )
33- Expect (err ).NotTo (HaveOccurred ())
24+ for _ , tt := range types {
25+ if ! slices .Contains (conditionsets .ConditionTypes , tt ) {
26+ t .Errorf ("append Type%s to conditionsets.ConditionTypes in this package's init function" , tt )
27+ }
28+ }
3429
35- for _ , r := range reasons {
36- Expect (r ).To (BeElementOf (conditionsets .ConditionReasons ), "Append Reason%s to conditionsets.ConditionReasons in this package's init function." , r )
37- }
38- for _ , r := range conditionsets .ConditionReasons {
39- 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 )
40- }
41- })
42- })
43- })
30+ for _ , tt := range conditionsets .ConditionTypes {
31+ if ! slices .Contains (types , tt ) {
32+ 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 )
33+ }
34+ }
35+ }
36+
37+ func TestOperatorReasonRegistration (t * testing.T ) {
38+ reasons , err := parseConstants ("Reason" )
39+ if err != nil {
40+ t .Fatalf ("unable to parse Reason constants %v" , err )
41+ }
42+
43+ for _ , r := range reasons {
44+ if ! slices .Contains (conditionsets .ConditionReasons , r ) {
45+ t .Errorf ("append Reason%s to conditionsets.ConditionReasons in this package's init function." , r )
46+ }
47+ }
48+ for _ , r := range conditionsets .ConditionReasons {
49+ if ! slices .Contains (reasons , r ) {
50+ 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 )
51+ }
52+ }
53+ }
4454
4555// parseConstants parses the values of the top-level constants in the current
4656// directory whose names start with the given prefix. When running as part of a
0 commit comments