Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move wait for log function into log.go file #35

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions utils/config.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package utils

import (
"strings"
"testing"
"time"

"github.com/stretchr/testify/require"
)

type Config struct {
TestAutoStart bool
TestAutoStart bool
}

func TestConfig(t *testing.T, snapName string, conf Config) {
Expand Down Expand Up @@ -50,20 +48,3 @@ func TestAutostartGlobal(t *testing.T, snapName string) {
require.False(t, SnapServicesActive(t, snapName))
})
}

func WaitForLogMessage(t *testing.T, snap, expectedLog string, since time.Time) {
const maxRetry = 10

for i := 1; i <= maxRetry; i++ {
time.Sleep(1 * time.Second)
t.Logf("Retry %d/%d: Waiting for expected content in logs: %s", i, maxRetry, expectedLog)

logs := SnapLogs(t, since, snap)
if strings.Contains(logs, expectedLog) {
t.Logf("Found expected content in logs: %s", expectedLog)
return
}
}

t.Fatalf("Time out: reached max %d retries.", maxRetry)
}
18 changes: 18 additions & 0 deletions utils/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os"
"strings"
"testing"
"time"
)

func logFileName(t *testing.T, label string) string {
Expand All @@ -28,3 +29,20 @@ func WriteLogFile(t *testing.T, label string, content string) error {
0644,
)
}

func WaitForLogMessage(t *testing.T, snap, expectedLog string, since time.Time) {
const maxRetry = 10

for i := 1; i <= maxRetry; i++ {
time.Sleep(1 * time.Second)
t.Logf("Retry %d/%d: Waiting for expected content in logs: %s", i, maxRetry, expectedLog)

logs := SnapLogs(t, since, snap)
if strings.Contains(logs, expectedLog) {
t.Logf("Found expected content in logs: %s", expectedLog)
return
}
}

t.Fatalf("Time out: reached max %d retries.", maxRetry)
}