From 4abe931611096371ec747218f9e563c617153b9c Mon Sep 17 00:00:00 2001 From: Jose Ignacio Lorenzo <74208929+joselo85@users.noreply.github.com> Date: Thu, 10 Nov 2022 16:00:26 -0300 Subject: [PATCH] [CONSUL-544] Test and Build Changes (#90) --- command/connect/envoy/envoy_test.go | 46 +--- .../envoy/testdata/defaults-windows.golden | 210 ------------------ 2 files changed, 7 insertions(+), 249 deletions(-) delete mode 100644 command/connect/envoy/testdata/defaults-windows.golden diff --git a/command/connect/envoy/envoy_test.go b/command/connect/envoy/envoy_test.go index 4bb2032da80d..31c078dc9967 100644 --- a/command/connect/envoy/envoy_test.go +++ b/command/connect/envoy/envoy_test.go @@ -24,11 +24,9 @@ import ( var update = flag.Bool("update", false, "update golden files") -const defaultOSPlatform = "linux" - func TestEnvoyCommand_noTabs(t *testing.T) { t.Parallel() - if strings.ContainsRune(New(nil, defaultOSPlatform).Help(), '\t') { + if strings.ContainsRune(New(nil).Help(), '\t') { t.Fatal("help has tabs") } } @@ -66,8 +64,8 @@ func TestEnvoyGateway_Validation(t *testing.T) { for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { ui := cli.NewMockUi() - c := New(ui, defaultOSPlatform) - c.init(defaultOSPlatform) + c := New(ui) + c.init() code := c.Run(tc.args) if code == 0 { @@ -122,7 +120,6 @@ type generateConfigTestCase struct { AgentSelf110 bool // fake the agent API from versions v1.10 and earlier WantArgs BootstrapTplArgs WantErr string - OSPlatform string } // This tests the args we use to generate the template directly because they @@ -163,28 +160,6 @@ func TestGenerateConfig(t *testing.T) { PrometheusScrapePath: "/metrics", }, }, - { - Name: "defaults-windows", - Flags: []string{"-proxy-id", "test-proxy"}, - WantArgs: BootstrapTplArgs{ - ProxyCluster: "test-proxy", - ProxyID: "test-proxy", - // We don't know this til after the lookup so it will be empty in the - // initial args call we are testing here. - ProxySourceService: "", - GRPC: GRPC{ - AgentAddress: "127.0.0.1", - AgentPort: "8502", // Note this is the gRPC port - }, - AdminAccessLogPath: "nul", - AdminBindAddress: "127.0.0.1", - AdminBindPort: "19000", - LocalAgentClusterName: xds.LocalAgentClusterName, - PrometheusBackendPort: "", - PrometheusScrapePath: "/metrics", - }, - OSPlatform: "windows", - }, { Name: "defaults-nodemeta", Flags: []string{"-proxy-id", "test-proxy", "-node-name", "test-node"}, @@ -1126,14 +1101,8 @@ func TestGenerateConfig(t *testing.T) { client, err := api.NewClient(&api.Config{Address: srv.URL, TLSConfig: api.TLSConfig{InsecureSkipVerify: true}}) require.NoError(t, err) - // Default OS Platform "linux". Custom value should be set in the test case - osPlatform := "linux" - if tc.OSPlatform == "windows" { - osPlatform = tc.OSPlatform - } - ui := cli.NewMockUi() - c := New(ui, osPlatform) + c := New(ui) // explicitly set the client to one which can connect to the httptest.Server c.client = client @@ -1142,7 +1111,7 @@ func TestGenerateConfig(t *testing.T) { args := append([]string{"-bootstrap"}, myFlags...) require.NoError(t, c.flags.Parse(args)) - code := c.run(c.flags.Args(), osPlatform) + code := c.run(c.flags.Args()) if tc.WantErr == "" { require.Equal(t, 0, code, ui.ErrorWriter.String()) } else { @@ -1153,8 +1122,7 @@ func TestGenerateConfig(t *testing.T) { // Verify we handled the env and flags right first to get correct template // args. - got, err := c.templateArgs(osPlatform) - + got, err := c.templateArgs() require.NoError(t, err) // Error cases should have returned above require.Equal(t, &tc.WantArgs, got) @@ -1247,7 +1215,7 @@ func TestEnvoy_GatewayRegistration(t *testing.T) { for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { ui := cli.NewMockUi() - c := New(ui, defaultOSPlatform) + c := New(ui) code := c.Run(tc.args) if code != 0 { diff --git a/command/connect/envoy/testdata/defaults-windows.golden b/command/connect/envoy/testdata/defaults-windows.golden deleted file mode 100644 index 59ef580c5d23..000000000000 --- a/command/connect/envoy/testdata/defaults-windows.golden +++ /dev/null @@ -1,210 +0,0 @@ -{ - "admin": { - "access_log_path": "nul", - "address": { - "socket_address": { - "address": "127.0.0.1", - "port_value": 19000 - } - } - }, - "node": { - "cluster": "test", - "id": "test-proxy", - "metadata": { - "namespace": "default", - "partition": "default" - } - }, - "layered_runtime": { - "layers": [ - { - "name": "base", - "static_layer": { - "re2.max_program_size.error_level": 1048576 - } - } - ] - }, - "static_resources": { - "clusters": [ - { - "name": "local_agent", - "ignore_health_on_host_removal": false, - "connect_timeout": "1s", - "type": "STATIC", - "http2_protocol_options": {}, - "loadAssignment": { - "clusterName": "local_agent", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "socket_address": { - "address": "127.0.0.1", - "port_value": 8502 - } - } - } - } - ] - } - ] - } - } - ] - }, - "stats_config": { - "stats_tags": [ - { - "regex": "^cluster\\.(?:passthrough~)?((?:([^.]+)~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", - "tag_name": "consul.destination.custom_hash" - }, - { - "regex": "^cluster\\.(?:passthrough~)?((?:[^.]+~)?(?:([^.]+)\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", - "tag_name": "consul.destination.service_subset" - }, - { - "regex": "^cluster\\.(?:passthrough~)?((?:[^.]+~)?(?:[^.]+\\.)?([^.]+)\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", - "tag_name": "consul.destination.service" - }, - { - "regex": "^cluster\\.(?:passthrough~)?((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.([^.]+)\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", - "tag_name": "consul.destination.namespace" - }, - { - "regex": "^cluster\\.(?:passthrough~)?((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:([^.]+)\\.)?[^.]+\\.internal[^.]*\\.[^.]+\\.consul\\.)", - "tag_name": "consul.destination.partition" - }, - { - "regex": "^cluster\\.(?:passthrough~)?((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?([^.]+)\\.internal[^.]*\\.[^.]+\\.consul\\.)", - "tag_name": "consul.destination.datacenter" - }, - { - "regex": "^cluster\\.([^.]+\\.(?:[^.]+\\.)?([^.]+)\\.external\\.[^.]+\\.consul\\.)", - "tag_name": "consul.destination.peer" - }, - { - "regex": "^cluster\\.(?:passthrough~)?((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.([^.]+)\\.[^.]+\\.consul\\.)", - "tag_name": "consul.destination.routing_type" - }, - { - "regex": "^cluster\\.(?:passthrough~)?((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.([^.]+)\\.consul\\.)", - "tag_name": "consul.destination.trust_domain" - }, - { - "regex": "^cluster\\.(?:passthrough~)?(((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+)\\.[^.]+\\.[^.]+\\.consul\\.)", - "tag_name": "consul.destination.target" - }, - { - "regex": "^cluster\\.(?:passthrough~)?(((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+)\\.consul\\.)", - "tag_name": "consul.destination.full_target" - }, - { - "regex": "^(?:tcp|http)\\.upstream(?:_peered)?\\.(([^.]+)(?:\\.[^.]+)?(?:\\.[^.]+)?\\.[^.]+\\.)", - "tag_name": "consul.upstream.service" - }, - { - "regex": "^(?:tcp|http)\\.upstream\\.([^.]+(?:\\.[^.]+)?(?:\\.[^.]+)?\\.([^.]+)\\.)", - "tag_name": "consul.upstream.datacenter" - }, - { - "regex": "^(?:tcp|http)\\.upstream_peered\\.([^.]+(?:\\.[^.]+)?\\.([^.]+)\\.)", - "tag_name": "consul.upstream.peer" - }, - { - "regex": "^(?:tcp|http)\\.upstream(?:_peered)?\\.([^.]+(?:\\.([^.]+))?(?:\\.[^.]+)?\\.[^.]+\\.)", - "tag_name": "consul.upstream.namespace" - }, - { - "regex": "^(?:tcp|http)\\.upstream\\.([^.]+(?:\\.[^.]+)?(?:\\.([^.]+))?\\.[^.]+\\.)", - "tag_name": "consul.upstream.partition" - }, - { - "regex": "^cluster\\.((?:([^.]+)~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", - "tag_name": "consul.custom_hash" - }, - { - "regex": "^cluster\\.((?:[^.]+~)?(?:([^.]+)\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", - "tag_name": "consul.service_subset" - }, - { - "regex": "^cluster\\.((?:[^.]+~)?(?:[^.]+\\.)?([^.]+)\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", - "tag_name": "consul.service" - }, - { - "regex": "^cluster\\.((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.([^.]+)\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+\\.consul\\.)", - "tag_name": "consul.namespace" - }, - { - "regex": "^cluster\\.((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?([^.]+)\\.internal[^.]*\\.[^.]+\\.consul\\.)", - "tag_name": "consul.datacenter" - }, - { - "regex": "^cluster\\.((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.([^.]+)\\.[^.]+\\.consul\\.)", - "tag_name": "consul.routing_type" - }, - { - "regex": "^cluster\\.((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.([^.]+)\\.consul\\.)", - "tag_name": "consul.trust_domain" - }, - { - "regex": "^cluster\\.(((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+)\\.[^.]+\\.[^.]+\\.consul\\.)", - "tag_name": "consul.target" - }, - { - "regex": "^cluster\\.(((?:[^.]+~)?(?:[^.]+\\.)?[^.]+\\.[^.]+\\.(?:[^.]+\\.)?[^.]+\\.[^.]+\\.[^.]+)\\.consul\\.)", - "tag_name": "consul.full_target" - }, - { - "tag_name": "local_cluster", - "fixed_value": "test" - }, - { - "tag_name": "consul.source.service", - "fixed_value": "test" - }, - { - "tag_name": "consul.source.namespace", - "fixed_value": "default" - }, - { - "tag_name": "consul.source.partition", - "fixed_value": "default" - }, - { - "tag_name": "consul.source.datacenter", - "fixed_value": "dc1" - } - ], - "use_all_default_tags": true - }, - "dynamic_resources": { - "lds_config": { - "ads": {}, - "resource_api_version": "V3" - }, - "cds_config": { - "ads": {}, - "resource_api_version": "V3" - }, - "ads_config": { - "api_type": "DELTA_GRPC", - "transport_api_version": "V3", - "grpc_services": { - "initial_metadata": [ - { - "key": "x-consul-token", - "value": "" - } - ], - "envoy_grpc": { - "cluster_name": "local_agent" - } - } - } - } -} -