2121package gateway
2222
2323import (
24+ "fmt"
2425 "testing"
2526
2627 bootstrapAPI "github.com/envoyproxy/go-control-plane/envoy/config/bootstrap/v3"
@@ -29,14 +30,18 @@ import (
2930 "github.com/arangodb/kube-arangodb/pkg/util"
3031)
3132
32- func renderAndPrintGatewayConfig (t * testing.T , cfg Config ) * bootstrapAPI.Bootstrap {
33+ func renderAndPrintGatewayConfig (t * testing.T , cfg Config , validates ... func ( t * testing. T , b * bootstrapAPI.Bootstrap )) {
3334 data , checksum , obj , err := cfg .RenderYAML ()
3435 require .NoError (t , err )
3536
3637 t .Logf ("Checksum: %s" , checksum )
3738 t .Log (string (data ))
3839
39- return obj
40+ for id := range validates {
41+ t .Run (fmt .Sprintf ("Validation%d" , id ), func (t * testing.T ) {
42+ validates [id ](t , obj )
43+ })
44+ }
4045}
4146
4247func Test_GatewayConfig (t * testing.T ) {
@@ -50,8 +55,27 @@ func Test_GatewayConfig(t *testing.T) {
5055 },
5156 },
5257 },
58+ }, func (t * testing.T , b * bootstrapAPI.Bootstrap ) {
59+ require .NotNil (t , b )
60+ require .NotNil (t , b .StaticResources )
61+ require .NotNil (t , b .StaticResources .Clusters )
62+ require .Len (t , b .StaticResources .Clusters , 1 )
63+ require .NotNil (t , b .StaticResources .Clusters [0 ])
64+ require .NotNil (t , b .StaticResources .Clusters [0 ].LoadAssignment )
65+ require .NotNil (t , b .StaticResources .Clusters [0 ].LoadAssignment .Endpoints )
66+ require .Len (t , b .StaticResources .Clusters [0 ].LoadAssignment .Endpoints , 1 )
67+ require .NotNil (t , b .StaticResources .Clusters [0 ].LoadAssignment .Endpoints [0 ])
68+ require .NotNil (t , b .StaticResources .Clusters [0 ].LoadAssignment .Endpoints [0 ].LbEndpoints )
69+ require .Len (t , b .StaticResources .Clusters [0 ].LoadAssignment .Endpoints [0 ].LbEndpoints , 1 )
70+ require .NotNil (t , b .StaticResources .Clusters [0 ].LoadAssignment .Endpoints [0 ].LbEndpoints [0 ])
71+ require .NotNil (t , b .StaticResources .Clusters [0 ].LoadAssignment .Endpoints [0 ].LbEndpoints [0 ].GetEndpoint ())
72+ require .NotNil (t , b .StaticResources .Clusters [0 ].LoadAssignment .Endpoints [0 ].LbEndpoints [0 ].GetEndpoint ().Address )
73+ require .NotNil (t , b .StaticResources .Clusters [0 ].LoadAssignment .Endpoints [0 ].LbEndpoints [0 ].GetEndpoint ().Address .GetSocketAddress ())
74+ require .EqualValues (t , "127.0.0.1" , b .StaticResources .Clusters [0 ].LoadAssignment .Endpoints [0 ].LbEndpoints [0 ].GetEndpoint ().Address .GetSocketAddress ().Address )
75+ require .EqualValues (t , 12345 , b .StaticResources .Clusters [0 ].LoadAssignment .Endpoints [0 ].LbEndpoints [0 ].GetEndpoint ().Address .GetSocketAddress ().GetPortValue ())
5376 })
5477 })
78+
5579 t .Run ("Default" , func (t * testing.T ) {
5680 renderAndPrintGatewayConfig (t , Config {
5781 DefaultDestination : ConfigDestination {
@@ -69,6 +93,7 @@ func Test_GatewayConfig(t *testing.T) {
6993 },
7094 })
7195 })
96+
7297 t .Run ("Default" , func (t * testing.T ) {
7398 renderAndPrintGatewayConfig (t , Config {
7499 DefaultDestination : ConfigDestination {
@@ -87,6 +112,7 @@ func Test_GatewayConfig(t *testing.T) {
87112 },
88113 })
89114 })
115+
90116 t .Run ("Default" , func (t * testing.T ) {
91117 renderAndPrintGatewayConfig (t , Config {
92118 DefaultDestination : ConfigDestination {
@@ -117,6 +143,38 @@ func Test_GatewayConfig(t *testing.T) {
117143 },
118144 })
119145 })
146+
147+ t .Run ("Default" , func (t * testing.T ) {
148+ renderAndPrintGatewayConfig (t , Config {
149+ DefaultDestination : ConfigDestination {
150+ Targets : []ConfigDestinationTarget {
151+ {
152+ Host : "127.0.0.1" ,
153+ Port : 12345 ,
154+ },
155+ },
156+ Path : util .NewType ("/test/path/" ),
157+ Type : util .NewType (ConfigDestinationTypeHTTPS ),
158+ },
159+ DefaultTLS : & ConfigTLS {
160+ CertificatePath : "/test" ,
161+ PrivateKeyPath : "/test12" ,
162+ },
163+ Destinations : ConfigDestinations {
164+ "/_test/" : {
165+ Targets : []ConfigDestinationTarget {
166+ {
167+ Host : "127.0.0.1" ,
168+ Port : 12346 ,
169+ },
170+ },
171+ Path : util .NewType ("/test/path/" ),
172+ Type : util .NewType (ConfigDestinationTypeHTTP ),
173+ },
174+ },
175+ })
176+ })
177+
120178 t .Run ("Default" , func (t * testing.T ) {
121179 renderAndPrintGatewayConfig (t , Config {
122180 DefaultDestination : ConfigDestination {
@@ -133,6 +191,17 @@ func Test_GatewayConfig(t *testing.T) {
133191 CertificatePath : "/test" ,
134192 PrivateKeyPath : "/test12" ,
135193 },
194+ SNI : []ConfigSNI {
195+ {
196+ ConfigTLS : ConfigTLS {
197+ CertificatePath : "/cp" ,
198+ PrivateKeyPath : "/pp" ,
199+ },
200+ ServerNames : []string {
201+ "example.com" ,
202+ },
203+ },
204+ },
136205 Destinations : ConfigDestinations {
137206 "/_test/" : {
138207 Targets : []ConfigDestinationTarget {
@@ -147,6 +216,7 @@ func Test_GatewayConfig(t *testing.T) {
147216 },
148217 })
149218 })
219+
150220 t .Run ("Default" , func (t * testing.T ) {
151221 renderAndPrintGatewayConfig (t , Config {
152222 DefaultDestination : ConfigDestination {
@@ -173,6 +243,15 @@ func Test_GatewayConfig(t *testing.T) {
173243 "example.com" ,
174244 },
175245 },
246+ {
247+ ConfigTLS : ConfigTLS {
248+ CertificatePath : "/c2" ,
249+ PrivateKeyPath : "/p2" ,
250+ },
251+ ServerNames : []string {
252+ "2.example.com" ,
253+ },
254+ },
176255 },
177256 Destinations : ConfigDestinations {
178257 "/_test/" : {
0 commit comments