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 5, 2024
1 parent 1ec8478 commit fcb8a19
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion e2e/sidecars/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
35 changes: 21 additions & 14 deletions e2e/sidecars/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
}
6 changes: 5 additions & 1 deletion e2e/sidecars/sidecar_def_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}
2 changes: 1 addition & 1 deletion e2e/sidecars/suite_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit fcb8a19

Please sign in to comment.