Skip to content

Commit

Permalink
chore: applied feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mojtaba-esk committed Nov 7, 2024
1 parent fcb8a19 commit 3b1fb56
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 29 deletions.
10 changes: 1 addition & 9 deletions e2e/sidecars/cmd_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 1 addition & 10 deletions e2e/sidecars/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 1 addition & 10 deletions e2e/sidecars/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions e2e/sidecars/suite_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}

0 comments on commit 3b1fb56

Please sign in to comment.