@@ -8,39 +8,49 @@ import (
8
8
"io/fs"
9
9
"strconv"
10
10
"strings"
11
-
12
- . "github.com/onsi/ginkgo/v2"
13
- . "github.com/onsi/gomega"
11
+ "testing"
14
12
15
13
"github.com/operator-framework/operator-controller/internal/conditionsets"
14
+
15
+ "golang.org/x/exp/slices" // replace with "slices" in go 1.21
16
16
)
17
17
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
+ }
23
23
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
+ }
34
29
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
+ }
44
54
45
55
// parseConstants parses the values of the top-level constants in the current
46
56
// directory whose names start with the given prefix. When running as part of a
0 commit comments