From 0985f630498bc05486fcdfe05d3076d036b69aa0 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Wed, 5 Jul 2023 17:47:28 -0400 Subject: [PATCH] fix tests --- ziti/cmd/create_config_router.go | 4 ++-- ziti/cmd/create_config_router_edge.go | 4 +--- ziti/cmd/create_config_router_edge_test.go | 14 ++++++-------- ziti/cmd/create_config_router_fabric.go | 5 +---- ziti/cmd/helpers/env_helpers.go | 4 ++++ 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/ziti/cmd/create_config_router.go b/ziti/cmd/create_config_router.go index 90f911353..0585827e1 100644 --- a/ziti/cmd/create_config_router.go +++ b/ziti/cmd/create_config_router.go @@ -83,8 +83,8 @@ func NewCmdCreateConfigRouter(routerOptions *CreateConfigRouterOptions) *NewCrea RenderedValues: data, } - cmd.AddCommand(NewCmdCreateConfigRouterEdge()) - cmd.AddCommand(NewCmdCreateConfigRouterFabric()) + cmd.AddCommand(NewCmdCreateConfigRouterEdge(routerOptions, data)) + cmd.AddCommand(NewCmdCreateConfigRouterFabric(routerOptions, data)) routerOptions.addCreateFlags(cmd.Command) routerOptions.addFlags(cmd.Command) diff --git a/ziti/cmd/create_config_router_edge.go b/ziti/cmd/create_config_router_edge.go index e4ea190fa..a823ca6c3 100644 --- a/ziti/cmd/create_config_router_edge.go +++ b/ziti/cmd/create_config_router_edge.go @@ -63,9 +63,7 @@ var ( var routerConfigEdgeTemplate string // NewCmdCreateConfigRouterEdge creates a command object for the "edge" command -func NewCmdCreateConfigRouterEdge() *cobra.Command { - data := &ConfigTemplateValues{} - routerOptions := &CreateConfigRouterOptions{} +func NewCmdCreateConfigRouterEdge(routerOptions *CreateConfigRouterOptions, data *ConfigTemplateValues) *cobra.Command { cmd := &cobra.Command{ Use: "edge", Short: "Create an edge router config", diff --git a/ziti/cmd/create_config_router_edge_test.go b/ziti/cmd/create_config_router_edge_test.go index d5ec38394..eebee8619 100644 --- a/ziti/cmd/create_config_router_edge_test.go +++ b/ziti/cmd/create_config_router_edge_test.go @@ -15,8 +15,7 @@ var defaultArgs = []string{"edge", "--routerName", "test-router"} var testHostname, _ = os.Hostname() func TestEdgeRouterAdvertisedAddress(t *testing.T) { - data := &ConfigTemplateValues{} - clearEnvAndInitializeTestData() + routerOpts := clearEnvAndInitializeTestData() routerAdvHostIp := "192.168.10.10" routerAdvHostDns := "controller01.zitinetwork.example.org" keys := map[string]string{ @@ -24,25 +23,24 @@ func TestEdgeRouterAdvertisedAddress(t *testing.T) { "ZITI_EDGE_ROUTER_PORT": "443", } // Defaults to hostname if nothing is set - createRouterConfig(defaultArgs, nil, keys) + _, data := createRouterConfig(defaultArgs, routerOpts, keys) require.Equal(t, testHostname, data.Router.Edge.AdvertisedHost, nil) // If IP override set, uses that value over hostname keys["ZITI_EDGE_ROUTER_IP_OVERRIDE"] = routerAdvHostIp - createRouterConfig(defaultArgs, nil, keys) - require.Equal(t, routerAdvHostIp, data.Router.Edge.AdvertisedHost, nil) + _, data2 := createRouterConfig(defaultArgs, routerOpts, keys) + require.Equal(t, routerAdvHostIp, data2.Router.Edge.AdvertisedHost, nil) // If advertised address set, uses that over IP override or hostname keys["ZITI_EDGE_ROUTER_ADVERTISED_HOST"] = routerAdvHostDns keys["ZITI_EDGE_ROUTER_IP_OVERRIDE"] = routerAdvHostIp - createRouterConfig(defaultArgs, nil, keys) - require.Equal(t, routerAdvHostDns, data.Router.Edge.AdvertisedHost, nil) + _, data3 := createRouterConfig(defaultArgs, routerOpts, keys) + require.Equal(t, routerAdvHostDns, data3.Router.Edge.AdvertisedHost, nil) } func TestTunnelerEnabledByDefault(t *testing.T) { // Setup options routerOptions := clearEnvAndInitializeTestData() - routerOptions.Output = defaultOutput // Create and run the CLI command without the tunnel flag config, _ := createRouterConfig([]string{"edge", "--routerName", "myRouter"}, routerOptions, nil) diff --git a/ziti/cmd/create_config_router_fabric.go b/ziti/cmd/create_config_router_fabric.go index 82aaf6722..395229a72 100644 --- a/ziti/cmd/create_config_router_fabric.go +++ b/ziti/cmd/create_config_router_fabric.go @@ -44,10 +44,7 @@ var ( var routerConfigFabricTemplate string // NewCmdCreateConfigRouterFabric creates a command object for the "fabric" command -func NewCmdCreateConfigRouterFabric() *cobra.Command { - data := &ConfigTemplateValues{} - routerOptions := &CreateConfigRouterOptions{} - +func NewCmdCreateConfigRouterFabric(routerOptions *CreateConfigRouterOptions, data *ConfigTemplateValues) *cobra.Command { cmd := &cobra.Command{ Use: "fabric", Short: "Create a fabric router config", diff --git a/ziti/cmd/helpers/env_helpers.go b/ziti/cmd/helpers/env_helpers.go index cf2de5541..4504b174c 100644 --- a/ziti/cmd/helpers/env_helpers.go +++ b/ziti/cmd/helpers/env_helpers.go @@ -100,6 +100,10 @@ func GetCtrlAdvertisedAddress() string { return getFromEnv(constants.CtrlAdvertisedAddressVarName, HostnameOrNetworkName) } +func GetEdgeRouterIpOvderride() string { + return getFromEnv(constants.ZitiEdgeRouterIPOverrideVarName, defaultValue("")) +} + func GetCtrlAdvertisedPort() string { return getFromEnv(constants.CtrlAdvertisedPortVarName, defaultValue(constants.DefaultCtrlAdvertisedPort)) }