Skip to content

Commit

Permalink
e2e
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Abro <[email protected]>
  • Loading branch information
AustinAbro321 committed Dec 13, 2024
1 parent 413ccd1 commit 9581a66
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 52 deletions.
23 changes: 8 additions & 15 deletions src/test/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bufio"
"errors"
"fmt"
"log/slog"
"os"
"regexp"
"runtime"
Expand All @@ -31,8 +32,6 @@ type ZarfE2ETest struct {
ApplianceModeKeep bool
}

var logRegex = regexp.MustCompile(`Saving log file to (?P<logFile>.*?\.log)`)

// GetCLIName looks at the OS and CPU architecture to determine which Zarf binary needs to be run.
func GetCLIName() string {
var binaryName string
Expand Down Expand Up @@ -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
Expand Down
22 changes: 1 addition & 21 deletions src/test/e2e/20_zarf_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}")
Expand Down Expand Up @@ -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()

Expand Down
4 changes: 1 addition & 3 deletions src/test/e2e/21_connect_creds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 5 additions & 9 deletions src/test/e2e/23_data_injection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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)
}
4 changes: 0 additions & 4 deletions src/test/e2e/24_variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9581a66

Please sign in to comment.