From 9a30908e17555ad4484db704c7b55a5470c63025 Mon Sep 17 00:00:00 2001 From: JoukoVirtanen Date: Mon, 2 Dec 2024 15:06:57 -0800 Subject: [PATCH] Moved createDirectory and deleteFile to base.go. Serializing a RuntimeConfig object to a config string rather than writing the string --- integration-tests/pkg/types/runtime_config.go | 6 ++--- integration-tests/suites/base.go | 10 +++++++++ .../suites/runtime_config_file.go | 22 +++++++------------ 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/integration-tests/pkg/types/runtime_config.go b/integration-tests/pkg/types/runtime_config.go index 6ad85449c1..69b42ca591 100644 --- a/integration-tests/pkg/types/runtime_config.go +++ b/integration-tests/pkg/types/runtime_config.go @@ -3,9 +3,9 @@ package types type RuntimeConfig struct { Networking struct { ExternalIps struct { - Enable bool - } - } + Enable bool `yaml:"enable"` + } `yaml:"externalIps"` + } `yaml:"networking"` } func (n *RuntimeConfig) Equal(other RuntimeConfig) bool { diff --git a/integration-tests/suites/base.go b/integration-tests/suites/base.go index 1e41e48934..4f75aba725 100644 --- a/integration-tests/suites/base.go +++ b/integration-tests/suites/base.go @@ -458,6 +458,16 @@ func (s *IntegrationTestSuiteBase) execShellCommand(command string) error { return err } +func (s *IntegrationTestSuiteBase) createDirectory(dir string) { + cmd := "mkdir " + dir + s.execShellCommand(cmd) +} + +func (s *IntegrationTestSuiteBase) deleteFile(file string) { + cmd := "rm " + file + s.execShellCommand(cmd) +} + func (s *IntegrationTestSuiteBase) waitForFileToBeDeleted(file string) error { timer := time.After(10 * time.Second) ticker := time.NewTicker(time.Second) diff --git a/integration-tests/suites/runtime_config_file.go b/integration-tests/suites/runtime_config_file.go index 940d727207..65afe0955c 100644 --- a/integration-tests/suites/runtime_config_file.go +++ b/integration-tests/suites/runtime_config_file.go @@ -2,8 +2,8 @@ package suites import ( "fmt" + "gopkg.in/yaml.v3" "path/filepath" - "strconv" "time" "github.com/stackrox/collector/integration-tests/pkg/assert" @@ -61,25 +61,19 @@ type RuntimeConfigFileTestSuite struct { ClientContainer string } -func (s *RuntimeConfigFileTestSuite) createDirectory(dir string) { - cmd := "mkdir " + dir - s.execShellCommand(cmd) -} - -func (s *RuntimeConfigFileTestSuite) deleteFile(file string) { - cmd := "rm " + file - s.execShellCommand(cmd) -} - func (s *RuntimeConfigFileTestSuite) setRuntimeConfig(runtimeConfigFile string, configStr string) { cmd := "echo '" + configStr + "' > " + runtimeConfigFile s.execShellCommand(cmd) } func (s *RuntimeConfigFileTestSuite) setExternalIpsEnable(runtimeConfigFile string, enable bool) { - configStr := `networking: - externalIps: - enable: ` + strconv.FormatBool(enable) + var runtimeConfig types.RuntimeConfig + runtimeConfig.Networking.ExternalIps.Enable = enable + + yamlBytes, err := yaml.Marshal(runtimeConfig) + s.Require().NoError(err) + + configStr := string(yamlBytes) s.setRuntimeConfig(runtimeConfigFile, configStr) }