From a31da69cf3017ee52a9e1cc63fdd4dbacc4b13a8 Mon Sep 17 00:00:00 2001 From: Spencer Date: Mon, 17 Jun 2024 13:59:26 +0100 Subject: [PATCH] fixed deprecated env prefix migration test --- src/core/config/config_test.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/core/config/config_test.go b/src/core/config/config_test.go index 59ac39f2f..3e390a780 100644 --- a/src/core/config/config_test.go +++ b/src/core/config/config_test.go @@ -482,12 +482,30 @@ func TestUpdateAgentConfig(t *testing.T) { func TestDeprecatedEnvPrefixMigration(t *testing.T) { want := true - t.Setenv("NMS_TLS_SKIP_VERIFY", "true") + curDir, err := os.Getwd() + require.NoError(t, err) - SetDefaults() - RegisterFlags() + tempConfDeleteFunc, err := sysutils.CopyFile(fmt.Sprintf("%s/%s", testCfgDir, emptyConfigFile), tempCfgFile) + defer func() { + err := tempConfDeleteFunc() + require.NoError(t, err, "deletion of temp config file failed") + }() + require.NoError(t, err) + + tempDynamicDeleteFunc, err := sysutils.CopyFile(fmt.Sprintf("%s/%s", testCfgDir, emptyConfigFile), tempDynamicCfgFile) + defer func() { + err := tempDynamicDeleteFunc() + require.NoError(t, err, "deletion of temp dynamic config file failed") + }() + require.NoError(t, err) + + cleanEnv(t, tempCfgFile, fmt.Sprintf("%s/%s", curDir, tempDynamicCfgFile)) + setEnvVariable(t, "tls_skip_verify", "true") + + config, err := GetConfig("1234") + require.NoError(t, err) - got := MigratedEnv + got := config.TLS.SkipVerify assert.Equal(t, want, got) }