From 3b1fb562d0caf056a8d0fad94161d99be2744efd Mon Sep 17 00:00:00 2001 From: Mojtaba Date: Thu, 7 Nov 2024 13:44:52 +0100 Subject: [PATCH] chore: applied feedback --- e2e/sidecars/cmd_exec_test.go | 10 +--------- e2e/sidecars/file_test.go | 11 +---------- e2e/sidecars/logs_test.go | 11 +---------- e2e/sidecars/suite_setup_test.go | 14 ++++++++++++++ 4 files changed, 17 insertions(+), 29 deletions(-) diff --git a/e2e/sidecars/cmd_exec_test.go b/e2e/sidecars/cmd_exec_test.go index b00ad24..30ef5d7 100644 --- a/e2e/sidecars/cmd_exec_test.go +++ b/e2e/sidecars/cmd_exec_test.go @@ -12,20 +12,12 @@ func (s *Suite) TestExecuteCommandInSidecar() { command = "echo " + cmdMsg ) - target, err := s.Knuu.NewInstance(namePrefix + "-target") - s.Require().NoError(err) - ctx := context.Background() - s.Require().NoError(target.Build().SetImage(ctx, alpineImage)) - s.Require().NoError(target.Build().SetArgs("tail", "-f", "/dev/null")) // Keep the container running - s.Require().NoError(target.Build().Commit(ctx)) sidecar := &testSidecar{ StartCommand: []string{"sh", "-c", "sleep infinity"}, } - - s.Require().NoError(target.Sidecars().Add(ctx, sidecar)) - s.Require().NoError(target.Execution().Start(ctx)) + s.startNewInstanceWithSidecar(ctx, namePrefix, sidecar) // Create a file in the sidecar instance out, err := sidecar.Instance().Execution().ExecuteCommand(ctx, command) diff --git a/e2e/sidecars/file_test.go b/e2e/sidecars/file_test.go index 6924c3d..9cbf6e5 100644 --- a/e2e/sidecars/file_test.go +++ b/e2e/sidecars/file_test.go @@ -10,21 +10,12 @@ func (s *Suite) TestDownloadFileFromRunningSidecar() { fileContent = "Hello World!" filePath = "/hello.txt" ) - - target, err := s.Knuu.NewInstance(namePrefix + "-target") - s.Require().NoError(err) - ctx := context.Background() - s.Require().NoError(target.Build().SetImage(ctx, alpineImage)) - s.Require().NoError(target.Build().SetArgs("tail", "-f", "/dev/null")) // Keep the container running - s.Require().NoError(target.Build().Commit(ctx)) sidecar := &testSidecar{ StartCommand: []string{"sh", "-c", "sleep infinity"}, } - - s.Require().NoError(target.Sidecars().Add(ctx, sidecar)) - s.Require().NoError(target.Execution().Start(ctx)) + s.startNewInstanceWithSidecar(ctx, namePrefix, sidecar) // Create a file in the sidecar instance out, err := sidecar.Instance().Execution().ExecuteCommand(ctx, "echo", "-n", fileContent, ">", filePath) diff --git a/e2e/sidecars/logs_test.go b/e2e/sidecars/logs_test.go index 0ca38ee..edefe10 100644 --- a/e2e/sidecars/logs_test.go +++ b/e2e/sidecars/logs_test.go @@ -17,22 +17,13 @@ func (s *Suite) TestLogsWithSidecar() { ) ctx := context.Background() - // Create a new instance - target, err := s.Knuu.NewInstance(namePrefix + "-target") - s.Require().NoError(err) - sidecar := &testSidecar{ StartCommand: []string{ "sh", "-c", fmt.Sprintf("while true; do echo '%s'; sleep 1; done", expectedLogMsg), }, } - - s.Require().NoError(target.Build().SetImage(ctx, alpineImage)) - s.Require().NoError(target.Build().SetStartCommand("sh", "-c", "sleep infinity")) - s.Require().NoError(target.Build().Commit(ctx)) - s.Require().NoError(target.Sidecars().Add(ctx, sidecar)) - s.Require().NoError(target.Execution().Start(ctx)) + s.startNewInstanceWithSidecar(ctx, namePrefix, sidecar) // Wait for a short duration to allow log generation s.Require().Eventually(func() bool { diff --git a/e2e/sidecars/suite_setup_test.go b/e2e/sidecars/suite_setup_test.go index 120fe94..3d52ee9 100644 --- a/e2e/sidecars/suite_setup_test.go +++ b/e2e/sidecars/suite_setup_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/celestiaorg/knuu/e2e" + "github.com/celestiaorg/knuu/pkg/instance" "github.com/celestiaorg/knuu/pkg/knuu" ) @@ -43,3 +44,16 @@ func (s *Suite) SetupSuite() { s.Executor.Kn = s.Knuu } + +func (s *Suite) startNewInstanceWithSidecar(ctx context.Context, namePrefix string, sidecar *testSidecar) *instance.Instance { + target, err := s.Knuu.NewInstance(namePrefix + "-target") + s.Require().NoError(err) + + s.Require().NoError(target.Build().SetImage(ctx, alpineImage)) + s.Require().NoError(target.Build().SetStartCommand("sh", "-c", "sleep infinity")) + s.Require().NoError(target.Build().Commit(ctx)) + s.Require().NoError(target.Sidecars().Add(ctx, sidecar)) + s.Require().NoError(target.Execution().Start(ctx)) + + return target +}