From 9581a66d6291cec1bccb9221baaac7c4e2a5fe43 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Fri, 13 Dec 2024 14:57:50 +0000 Subject: [PATCH] e2e Signed-off-by: Austin Abro --- src/test/common.go | 23 ++++++++--------------- src/test/e2e/20_zarf_init_test.go | 22 +--------------------- src/test/e2e/21_connect_creds_test.go | 4 +--- src/test/e2e/23_data_injection_test.go | 14 +++++--------- src/test/e2e/24_variables_test.go | 4 ---- 5 files changed, 15 insertions(+), 52 deletions(-) diff --git a/src/test/common.go b/src/test/common.go index 64992bf7d4..c741aee02a 100644 --- a/src/test/common.go +++ b/src/test/common.go @@ -8,6 +8,7 @@ import ( "bufio" "errors" "fmt" + "log/slog" "os" "regexp" "runtime" @@ -31,8 +32,6 @@ type ZarfE2ETest struct { ApplianceModeKeep bool } -var logRegex = regexp.MustCompile(`Saving log file to (?P.*?\.log)`) - // GetCLIName looks at the OS and CPU architecture to determine which Zarf binary needs to be run. func GetCLIName() string { var binaryName string @@ -123,24 +122,18 @@ func (e2e *ZarfE2ETest) GetMismatchedArch() string { } } -// GetLogFileContents gets the log file contents from a given run's std error. -func (e2e *ZarfE2ETest) GetLogFileContents(t *testing.T, stdErr string) string { - get, err := helpers.MatchRegex(logRegex, stdErr) - require.NoError(t, err) - logFile := get("logFile") - logContents, err := os.ReadFile(logFile) - require.NoError(t, err) - return string(logContents) -} - -// GetLogConfig returns the default log configuration for the tests. -func (e2e *ZarfE2ETest) GetLogConfig() logger.Config { - return logger.Config{ +// GetLogger returns the default log configuration for the tests. +func (e2e *ZarfE2ETest) GetLogger(t *testing.T) *slog.Logger { + t.Helper() + cfg := logger.Config{ Level: logger.Debug, Format: logger.FormatConsole, Destination: logger.DestinationDefault, // Stderr Color: false, } + l, err := logger.New(cfg) + require.NoError(t, err) + return l } // GetZarfVersion returns the current build/zarf version diff --git a/src/test/e2e/20_zarf_init_test.go b/src/test/e2e/20_zarf_init_test.go index 43277bef97..15b9b9344b 100644 --- a/src/test/e2e/20_zarf_init_test.go +++ b/src/test/e2e/20_zarf_init_test.go @@ -64,7 +64,7 @@ func TestZarfInit(t *testing.T) { } // run `zarf init` - _, initStdErr, err := e2e.Zarf(t, "init", "--components="+initComponents, "--nodeport", "31337", "-l", "trace", "--confirm") + _, _, err = e2e.Zarf(t, "init", "--components="+initComponents, "--nodeport", "31337", "--confirm") require.NoError(t, err) // Verify that any state secrets were not included in the log @@ -76,9 +76,6 @@ func TestZarfInit(t *testing.T) { err = json.Unmarshal(stateJSON, &state) require.NoError(t, err) - // replace this with a call to tee the log file - e2e.GetLogFileContents(t, e2e.StripMessageFormatting(initStdErr)) - if e2e.ApplianceMode { // make sure that we upgraded `k3s` correctly and are running the correct version - this should match that found in `packages/distros/k3s` kubeletVersion, _, err := e2e.Kubectl(t, "get", "nodes", "-o", "jsonpath={.items[0].status.nodeInfo.kubeletVersion}") @@ -106,23 +103,6 @@ func TestZarfInit(t *testing.T) { _, _, _ = e2e.Kubectl(t, "scale", "deploy", "-n", "zarf", "agent-hook", "--replicas=1") //nolint:errcheck } -// func checkLogForSensitiveState(t *testing.T, logText string, zarfState types.ZarfState) { -// t.Helper() - -// require.NotContains(t, logText, zarfState.AgentTLS.CA) -// require.NotContains(t, logText, string(zarfState.AgentTLS.CA)) -// require.NotContains(t, logText, zarfState.AgentTLS.Cert) -// require.NotContains(t, logText, string(zarfState.AgentTLS.Cert)) -// require.NotContains(t, logText, zarfState.AgentTLS.Key) -// require.NotContains(t, logText, string(zarfState.AgentTLS.Key)) -// require.NotContains(t, logText, zarfState.ArtifactServer.PushToken) -// require.NotContains(t, logText, zarfState.GitServer.PullPassword) -// require.NotContains(t, logText, zarfState.GitServer.PushPassword) -// require.NotContains(t, logText, zarfState.RegistryInfo.PullPassword) -// require.NotContains(t, logText, zarfState.RegistryInfo.PushPassword) -// require.NotContains(t, logText, zarfState.RegistryInfo.Secret) -// } - func verifyZarfNamespaceLabels(t *testing.T) { t.Helper() diff --git a/src/test/e2e/21_connect_creds_test.go b/src/test/e2e/21_connect_creds_test.go index 64b7bd2ecc..c994133557 100644 --- a/src/test/e2e/21_connect_creds_test.go +++ b/src/test/e2e/21_connect_creds_test.go @@ -25,9 +25,7 @@ type RegistryResponse struct { func TestConnectAndCreds(t *testing.T) { t.Log("E2E: Connect") ctx := context.Background() - l, err := logger.New(e2e.GetLogConfig()) - require.NoError(t, err) - ctx = logger.WithContext(ctx, l) + ctx = logger.WithContext(ctx, e2e.GetLogger(t)) prevAgentSecretData, _, err := e2e.Kubectl(t, "get", "secret", "agent-hook-tls", "-n", "zarf", "-o", "jsonpath={.data}") require.NoError(t, err) diff --git a/src/test/e2e/23_data_injection_test.go b/src/test/e2e/23_data_injection_test.go index c7400b240e..6c1655c711 100644 --- a/src/test/e2e/23_data_injection_test.go +++ b/src/test/e2e/23_data_injection_test.go @@ -10,17 +10,17 @@ import ( "net/http" "path/filepath" "testing" - "time" "github.com/stretchr/testify/require" "github.com/zarf-dev/zarf/src/pkg/cluster" - "github.com/zarf-dev/zarf/src/pkg/utils/exec" + "github.com/zarf-dev/zarf/src/pkg/logger" ) func TestDataInjection(t *testing.T) { t.Log("E2E: Data injection") ctx := context.Background() + ctx = logger.WithContext(ctx, e2e.GetLogger(t)) path := fmt.Sprintf("build/zarf-package-kiwix-%s-3.5.0.tar", e2e.Arch) @@ -29,7 +29,7 @@ func TestDataInjection(t *testing.T) { // Repeat the injection action 3 times to ensure the data injection is idempotent and doesn't fail to perform an upgrade for i := 0; i < 3; i++ { - runDataInjection(ctx, t, path) + runDataInjection(t, path) } // Verify the file and injection marker were created @@ -65,12 +65,8 @@ func TestDataInjection(t *testing.T) { require.FileExists(t, filepath.Join(sbomPath, "kiwix", "zarf-component-kiwix-serve.json"), "The data-injection component should have an SBOM json") } -func runDataInjection(ctx context.Context, t *testing.T, path string) { - // Limit this deploy to 5 minutes - ctx, cancel := context.WithTimeout(ctx, 5*time.Minute) - defer cancel() - +func runDataInjection(t *testing.T, path string) { // Deploy the data injection example - stdOut, stdErr, err := exec.CmdWithContext(ctx, exec.PrintCfg(), e2e.ZarfBinPath, "package", "deploy", path, "-l", "trace", "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "deploy", path, "--confirm", "--timeout", "5m") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/24_variables_test.go b/src/test/e2e/24_variables_test.go index 255988d4f8..62c2030995 100644 --- a/src/test/e2e/24_variables_test.go +++ b/src/test/e2e/24_variables_test.go @@ -64,10 +64,6 @@ func TestVariables(t *testing.T) { // Verify that the sensitive variable 'unicorn-land' was not printed to the screen require.NotContains(t, stdOut, "unicorn-land") - logText := e2e.GetLogFileContents(t, e2e.StripMessageFormatting(stdErr)) - // Verify that the sensitive variable 'unicorn-land' was not included in the log - require.NotContains(t, logText, "unicorn-land") - // Verify the terraform file was templated correctly outputTF, err := os.ReadFile(tfPath) require.NoError(t, err)