diff --git a/utils/config.go b/utils/config.go index af0284f..72040a6 100644 --- a/utils/config.go +++ b/utils/config.go @@ -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) { @@ -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) -} diff --git a/utils/log.go b/utils/log.go index 47642e2..32d8381 100644 --- a/utils/log.go +++ b/utils/log.go @@ -4,6 +4,7 @@ import ( "os" "strings" "testing" + "time" ) func logFileName(t *testing.T, label string) string { @@ -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) +}