@@ -16,26 +16,36 @@ limitations under the License.
16
16
package v1alpha1
17
17
18
18
import (
19
- "encoding/json"
20
19
"testing"
21
20
22
21
"github.com/google/go-cmp/cmp"
22
+ "github.com/knative/pkg/apis/duck"
23
23
duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1"
24
24
corev1 "k8s.io/api/core/v1"
25
- "k8s.io/apimachinery/pkg/util/intstr"
26
25
)
27
26
28
- func TestGeneration (t * testing.T ) {
29
- r := ClusterIngress {}
30
- if a := r .GetGeneration (); a != 0 {
31
- t .Errorf ("empty ClusterIngress generation should be 0 was: %d" , a )
27
+ func TestClusterIngressDuckTypes (t * testing.T ) {
28
+ var emptyGen duckv1alpha1.Generation
29
+
30
+ tests := []struct {
31
+ name string
32
+ t duck.Implementable
33
+ }{{
34
+ name : "generational" ,
35
+ t : & emptyGen ,
36
+ }, {
37
+ name : "conditions" ,
38
+ t : & duckv1alpha1.Conditions {},
39
+ }}
40
+
41
+ for _ , test := range tests {
42
+ t .Run (test .name , func (t * testing.T ) {
43
+ err := duck .VerifyType (& ClusterIngress {}, test .t )
44
+ if err != nil {
45
+ t .Errorf ("VerifyType(ClusterIngress, %T) = %v" , test .t , err )
46
+ }
47
+ })
32
48
}
33
-
34
- r .SetGeneration (5 )
35
- if e , a := int64 (5 ), r .GetGeneration (); e != a {
36
- t .Errorf ("getgeneration mismatch expected: %d got: %d" , e , a )
37
- }
38
-
39
49
}
40
50
41
51
func TestGetGroupVersionKind (t * testing.T ) {
@@ -46,43 +56,6 @@ func TestGetGroupVersionKind(t *testing.T) {
46
56
}
47
57
}
48
58
49
- func TestGetSpecJSON (t * testing.T ) {
50
- ci := ClusterIngress {
51
- Spec : IngressSpec {
52
- TLS : []ClusterIngressTLS {{
53
- SecretNamespace : "secret-space" ,
54
- SecretName : "secret-name" ,
55
- }},
56
- Rules : []ClusterIngressRule {{
57
- Hosts : []string {"example.com" },
58
- HTTP : & HTTPClusterIngressRuleValue {
59
- Paths : []HTTPClusterIngressPath {{
60
- Splits : []ClusterIngressBackendSplit {{
61
- Backend : & ClusterIngressBackend {
62
- ServiceName : "revision-000" ,
63
- ServiceNamespace : "default" ,
64
- ServicePort : intstr .FromInt (8080 ),
65
- },
66
- }},
67
- Retries : & HTTPRetry {
68
- Attempts : 3 ,
69
- },
70
- }},
71
- },
72
- }},
73
- },
74
- }
75
- bytes , err := ci .GetSpecJSON ()
76
- if err != nil {
77
- t .Fatalf ("Saw %v, wanted: nil" , err )
78
- }
79
- cis := IngressSpec {}
80
- json .Unmarshal (bytes , & cis )
81
- if diff := cmp .Diff (ci .Spec , cis ); diff != "" {
82
- t .Errorf ("Unexpected diff (-want, +got) = %v" , diff )
83
- }
84
- }
85
-
86
59
func TestTypicalFlow (t * testing.T ) {
87
60
r := & ClusterIngress {}
88
61
r .Status .InitializeConditions ()
0 commit comments