github.com/cilium/cilium@v1.16.2/operator/pkg/gateway-api/gateway_status_test.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package gateway_api 5 6 import ( 7 "testing" 8 9 "github.com/google/go-cmp/cmp" 10 "github.com/google/go-cmp/cmp/cmpopts" 11 "github.com/stretchr/testify/assert" 12 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 13 gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" 14 ) 15 16 func Test_gatewayStatusScheduledCondition(t *testing.T) { 17 type args struct { 18 gw *gatewayv1.Gateway 19 scheduled bool 20 msg string 21 } 22 tests := []struct { 23 name string 24 args args 25 want metav1.Condition 26 }{ 27 { 28 name: "scheduled", 29 args: args{ 30 gw: &gatewayv1.Gateway{ 31 ObjectMeta: metav1.ObjectMeta{ 32 Generation: 100, 33 }, 34 }, 35 scheduled: true, 36 msg: "Scheduled Gateway", 37 }, 38 want: metav1.Condition{ 39 Type: "Accepted", 40 Status: "True", 41 ObservedGeneration: 100, 42 Reason: "Accepted", 43 Message: "Scheduled Gateway", 44 }, 45 }, 46 { 47 name: "non-scheduled", 48 args: args{ 49 gw: &gatewayv1.Gateway{ 50 ObjectMeta: metav1.ObjectMeta{ 51 Generation: 100, 52 }, 53 }, 54 scheduled: false, 55 msg: "Invalid Gateway", 56 }, 57 want: metav1.Condition{ 58 Type: "Accepted", 59 Status: "False", 60 ObservedGeneration: 100, 61 Reason: "NoResources", 62 Message: "Invalid Gateway", 63 }, 64 }, 65 } 66 for _, tt := range tests { 67 t.Run(tt.name, func(t *testing.T) { 68 got := gatewayStatusAcceptedCondition(tt.args.gw, tt.args.scheduled, tt.args.msg) 69 assert.True(t, cmp.Equal(got, tt.want, cmpopts.IgnoreFields(metav1.Condition{}, "LastTransitionTime")), "gatewayStatusAcceptedCondition() = %v, want %v", got, tt.want) 70 }) 71 } 72 } 73 74 func Test_gatewayStatusReadyCondition(t *testing.T) { 75 type args struct { 76 gw *gatewayv1.Gateway 77 ready bool 78 msg string 79 } 80 tests := []struct { 81 name string 82 args args 83 want metav1.Condition 84 }{ 85 { 86 name: "ready", 87 args: args{ 88 gw: &gatewayv1.Gateway{ 89 ObjectMeta: metav1.ObjectMeta{ 90 Generation: 100, 91 }, 92 }, 93 ready: true, 94 msg: "Listener Ready", 95 }, 96 want: metav1.Condition{ 97 Type: "Ready", 98 Status: "True", 99 ObservedGeneration: 100, 100 Reason: "Ready", 101 Message: "Listener Ready", 102 }, 103 }, 104 { 105 name: "unready", 106 args: args{ 107 gw: &gatewayv1.Gateway{ 108 ObjectMeta: metav1.ObjectMeta{ 109 Generation: 100, 110 }, 111 }, 112 ready: false, 113 msg: "Listener Pending", 114 }, 115 want: metav1.Condition{ 116 Type: "Ready", 117 Status: "False", 118 ObservedGeneration: 100, 119 Reason: "ListenersNotReady", 120 Message: "Listener Pending", 121 }, 122 }, 123 } 124 for _, tt := range tests { 125 t.Run(tt.name, func(t *testing.T) { 126 got := gatewayStatusReadyCondition(tt.args.gw, tt.args.ready, tt.args.msg) 127 assert.True(t, cmp.Equal(got, tt.want, cmpopts.IgnoreFields(metav1.Condition{}, "LastTransitionTime")), "gatewayStatusAcceptedCondition() = %v, want %v", got, tt.want) 128 }) 129 } 130 } 131 132 func Test_gatewayListenerProgrammedCondition(t *testing.T) { 133 type args struct { 134 gw *gatewayv1.Gateway 135 ready bool 136 msg string 137 } 138 tests := []struct { 139 name string 140 args args 141 want metav1.Condition 142 }{ 143 { 144 name: "ready", 145 args: args{ 146 gw: &gatewayv1.Gateway{ 147 ObjectMeta: metav1.ObjectMeta{ 148 Generation: 100, 149 }, 150 }, 151 ready: true, 152 msg: "Listener Ready", 153 }, 154 want: metav1.Condition{ 155 Type: "Programmed", 156 Status: "True", 157 ObservedGeneration: 100, 158 Reason: "Programmed", 159 Message: "Listener Ready", 160 }, 161 }, 162 { 163 name: "unready", 164 args: args{ 165 gw: &gatewayv1.Gateway{ 166 ObjectMeta: metav1.ObjectMeta{ 167 Generation: 100, 168 }, 169 }, 170 ready: false, 171 msg: "Listener Pending", 172 }, 173 want: metav1.Condition{ 174 Type: "Programmed", 175 Status: "False", 176 ObservedGeneration: 100, 177 Reason: "Pending", 178 Message: "Listener Pending", 179 }, 180 }, 181 } 182 for _, tt := range tests { 183 t.Run(tt.name, func(t *testing.T) { 184 got := gatewayListenerProgrammedCondition(tt.args.gw, tt.args.ready, tt.args.msg) 185 assert.True(t, cmp.Equal(got, tt.want, cmpopts.IgnoreFields(metav1.Condition{}, "LastTransitionTime")), "gatewayStatusAcceptedCondition() = %v, want %v", got, tt.want) 186 }) 187 } 188 }