From fcb8a195b19184873611d699e75305393b4f1c44 Mon Sep 17 00:00:00 2001 From: Mojtaba Date: Tue, 5 Nov 2024 11:39:32 +0100 Subject: [PATCH] chore: applied feedback --- e2e/sidecars/file_test.go | 2 +- e2e/sidecars/logs_test.go | 35 +++++++++++++++++++------------- e2e/sidecars/sidecar_def_test.go | 6 +++++- e2e/sidecars/suite_setup_test.go | 2 +- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/e2e/sidecars/file_test.go b/e2e/sidecars/file_test.go index dd801a9..6924c3d 100644 --- a/e2e/sidecars/file_test.go +++ b/e2e/sidecars/file_test.go @@ -31,7 +31,7 @@ func (s *Suite) TestDownloadFileFromRunningSidecar() { s.Require().NoError(err, "executing command output: %v", out) gotContent, err := sidecar.Instance().Storage().GetFileBytes(ctx, filePath) - s.Require().NoError(err, "Error getting file bytes") + s.Require().NoError(err, "Failed to read file %s from sidecar: %v", filePath, err) s.Assert().Equal(fileContent, string(gotContent)) } diff --git a/e2e/sidecars/logs_test.go b/e2e/sidecars/logs_test.go index 7b9961f..0ca38ee 100644 --- a/e2e/sidecars/logs_test.go +++ b/e2e/sidecars/logs_test.go @@ -4,13 +4,17 @@ import ( "context" "fmt" "io" + "strings" "time" ) -const expectedLogMsg = "Hello World" - func (s *Suite) TestLogsWithSidecar() { - const namePrefix = "logs-sidecar" + const ( + namePrefix = "logs-sidecar" + expectedLogMsg = "Hello World" + timeout = 10 * time.Second + interval = 1 * time.Second + ) ctx := context.Background() // Create a new instance @@ -31,15 +35,18 @@ func (s *Suite) TestLogsWithSidecar() { s.Require().NoError(target.Execution().Start(ctx)) // Wait for a short duration to allow log generation - time.Sleep(5 * time.Second) - - logStream, err := sidecar.Instance().Monitoring().Logs(ctx) - s.Require().NoError(err) - defer logStream.Close() - - logs, err := io.ReadAll(logStream) - s.Require().NoError(err) - - logOutput := string(logs) - s.Contains(logOutput, expectedLogMsg) + s.Require().Eventually(func() bool { + logStream, err := sidecar.Instance().Monitoring().Logs(ctx) + if err != nil { + return false + } + defer logStream.Close() + + logs, err := io.ReadAll(logStream) + if err != nil { + return false + } + + return strings.Contains(string(logs), expectedLogMsg) + }, timeout, interval, "failed to get expected log message") } diff --git a/e2e/sidecars/sidecar_def_test.go b/e2e/sidecars/sidecar_def_test.go index 05cbffa..c9f80ae 100644 --- a/e2e/sidecars/sidecar_def_test.go +++ b/e2e/sidecars/sidecar_def_test.go @@ -42,6 +42,9 @@ func (s *testSidecar) PreStart(ctx context.Context) error { if s.instance == nil { return errors.New("instance not initialized") } + if len(s.StartCommand) == 0 { + return errors.New("start command not configured") + } return nil } @@ -55,6 +58,7 @@ func (s *testSidecar) Clone(namePrefix string) (instance.SidecarManager, error) return nil, err } return &testSidecar{ - instance: clone, + instance: clone, + StartCommand: append([]string{}, s.StartCommand...), }, nil } diff --git a/e2e/sidecars/suite_setup_test.go b/e2e/sidecars/suite_setup_test.go index bc59070..120fe94 100644 --- a/e2e/sidecars/suite_setup_test.go +++ b/e2e/sidecars/suite_setup_test.go @@ -14,7 +14,7 @@ import ( const ( testTimeout = time.Minute * 5 // the same time that is used in the ci/cd pipeline - alpineImage = "alpine:latest" + alpineImage = "alpine:3.20.3" ) type Suite struct {