From e0bb83b40d7820330bbe8e38a9f538d617d8410e Mon Sep 17 00:00:00 2001 From: Tiexin Guo Date: Tue, 10 Sep 2024 17:59:23 +0800 Subject: [PATCH] chore: add some comments --- tests/main_test.go | 1 + tests/utils.go | 3 +++ 2 files changed, 4 insertions(+) diff --git a/tests/main_test.go b/tests/main_test.go index 387e872a..dd704c07 100644 --- a/tests/main_test.go +++ b/tests/main_test.go @@ -26,6 +26,7 @@ import ( . "github.com/canonical/pebble/tests" ) +// TestMain does extra setup before executing tests. func TestMain(m *testing.M) { goBuild := exec.Command("go", "build", "-o", "../pebble", "../cmd/pebble") if err := goBuild.Run(); err != nil { diff --git a/tests/utils.go b/tests/utils.go index 803d2f8a..b3ea5555 100644 --- a/tests/utils.go +++ b/tests/utils.go @@ -28,6 +28,7 @@ import ( "time" ) +// CreateLayer creates a layer file in the Pebble dir using the name and content given. func CreateLayer(t *testing.T, pebbleDir string, layerFileName string, layerYAML string) { t.Helper() @@ -44,6 +45,7 @@ func CreateLayer(t *testing.T, pebbleDir string, layerFileName string, layerYAML } } +// PebbleRun runs the Pebble daemon and returns a channel for logs. func PebbleRun(t *testing.T, pebbleDir string) <-chan string { t.Helper() @@ -82,6 +84,7 @@ func PebbleRun(t *testing.T, pebbleDir string) <-chan string { return logsCh } +// WaitForLogs reads from the channel (returned by PebbleRun) and checks if all expected logs are found within specified timeout duration. func WaitForLogs(logsCh <-chan string, expectedLogs []string, timeout time.Duration) error { receivedLogs := make(map[string]struct{}) start := time.Now()