@@ -11,7 +11,6 @@ import (
11
11
"net/http"
12
12
"net/http/httptest"
13
13
"net/url"
14
- "reflect"
15
14
"strconv"
16
15
"strings"
17
16
"testing"
@@ -25,6 +24,7 @@ import (
25
24
"github.com/hashicorp/consul/agent/structs"
26
25
"github.com/hashicorp/consul/agent/token"
27
26
tokenStore "github.com/hashicorp/consul/agent/token"
27
+ "github.com/hashicorp/consul/agent/xds/proxysupport"
28
28
"github.com/hashicorp/consul/api"
29
29
"github.com/hashicorp/consul/lib"
30
30
"github.com/hashicorp/consul/sdk/testutil"
@@ -1175,39 +1175,65 @@ func TestAgent_Checks_ACLFilter(t *testing.T) {
1175
1175
1176
1176
func TestAgent_Self (t * testing.T ) {
1177
1177
t .Parallel ()
1178
- a := NewTestAgent (t , t .Name (), `
1179
- node_meta {
1180
- somekey = "somevalue"
1181
- }
1182
- ` )
1183
- defer a .Shutdown ()
1184
1178
1185
- testrpc .WaitForTestAgent (t , a .RPC , "dc1" )
1186
- req , _ := http .NewRequest ("GET" , "/v1/agent/self" , nil )
1187
- obj , err := a .srv .AgentSelf (nil , req )
1188
- if err != nil {
1189
- t .Fatalf ("err: %v" , err )
1179
+ cases := map [string ]struct {
1180
+ hcl string
1181
+ expectXDS bool
1182
+ }{
1183
+ "normal" : {
1184
+ hcl : `
1185
+ node_meta {
1186
+ somekey = "somevalue"
1187
+ }
1188
+ ` ,
1189
+ expectXDS : true ,
1190
+ },
1191
+ "no grpc" : {
1192
+ hcl : `
1193
+ node_meta {
1194
+ somekey = "somevalue"
1195
+ }
1196
+ ports = {
1197
+ grpc = -1
1198
+ }
1199
+ ` ,
1200
+ expectXDS : false ,
1201
+ },
1190
1202
}
1191
1203
1192
- val := obj .(Self )
1193
- if int (val .Member .Port ) != a .Config .SerfPortLAN {
1194
- t .Fatalf ("incorrect port: %v" , obj )
1195
- }
1204
+ for name , tc := range cases {
1205
+ tc := tc
1206
+ t .Run (name , func (t * testing.T ) {
1207
+ a := NewTestAgent (t , t .Name (), tc .hcl )
1208
+ defer a .Shutdown ()
1196
1209
1197
- if val .DebugConfig ["SerfPortLAN" ].(int ) != a .Config .SerfPortLAN {
1198
- t .Fatalf ("incorrect port: %v" , obj )
1199
- }
1210
+ testrpc .WaitForTestAgent (t , a .RPC , "dc1" )
1211
+ req , _ := http .NewRequest ("GET" , "/v1/agent/self" , nil )
1212
+ obj , err := a .srv .AgentSelf (nil , req )
1213
+ require .NoError (t , err )
1200
1214
1201
- cs , err := a .GetLANCoordinate ()
1202
- if err != nil {
1203
- t .Fatalf ("err: %v" , err )
1204
- }
1205
- if c := cs [a .config .SegmentName ]; ! reflect .DeepEqual (c , val .Coord ) {
1206
- t .Fatalf ("coordinates are not equal: %v != %v" , c , val .Coord )
1207
- }
1208
- delete (val .Meta , structs .MetaSegmentKey ) // Added later, not in config.
1209
- if ! reflect .DeepEqual (a .config .NodeMeta , val .Meta ) {
1210
- t .Fatalf ("meta fields are not equal: %v != %v" , a .config .NodeMeta , val .Meta )
1215
+ val := obj .(Self )
1216
+ require .Equal (t , a .Config .SerfPortLAN , int (val .Member .Port ))
1217
+ require .Equal (t , a .Config .SerfPortLAN , val .DebugConfig ["SerfPortLAN" ].(int ))
1218
+
1219
+ cs , err := a .GetLANCoordinate ()
1220
+ require .NoError (t , err )
1221
+ require .Equal (t , cs [a .config .SegmentName ], val .Coord )
1222
+
1223
+ delete (val .Meta , structs .MetaSegmentKey ) // Added later, not in config.
1224
+ require .Equal (t , a .config .NodeMeta , val .Meta )
1225
+
1226
+ if tc .expectXDS {
1227
+ require .NotNil (t , val .XDS , "xds component missing when gRPC is enabled" )
1228
+ require .Equal (t ,
1229
+ map [string ][]string {"envoy" : proxysupport .EnvoyVersions },
1230
+ val .XDS .SupportedProxies ,
1231
+ )
1232
+
1233
+ } else {
1234
+ require .Nil (t , val .XDS , "xds component should be missing when gRPC is disabled" )
1235
+ }
1236
+ })
1211
1237
}
1212
1238
}
1213
1239
0 commit comments