fix: replace time.sleep() with checking logs (#899)

Signed-off-by: Lisca Ana-Roberta <ana.kagome@yahoo.com>
This commit is contained in:
Lisca Ana-Roberta
2022-10-21 21:17:06 +03:00
committed by GitHub
parent 00e65bd32b
commit 26d982becb
5 changed files with 139 additions and 6 deletions
+16 -1
View File
@@ -8,6 +8,7 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"path"
@@ -419,7 +420,18 @@ func TestCVESearch(t *testing.T) {
Search: searchConfig,
}
logFile, err := os.CreateTemp(t.TempDir(), "zot-log*.txt")
if err != nil {
panic(err)
}
logPath := logFile.Name()
defer os.Remove(logPath)
writers := io.MultiWriter(os.Stdout, logFile)
ctlr := api.NewController(conf)
ctlr.Log.Logger = ctlr.Log.Output(writers)
go func() {
// this blocks
@@ -438,7 +450,10 @@ func TestCVESearch(t *testing.T) {
}
// Wait for trivy db to download
time.Sleep(90 * time.Second)
_, err = ReadLogFileAndSearchString(logPath, "DB update completed, next update scheduled", 90*time.Second)
if err != nil {
panic(err)
}
defer func() {
ctx := context.Background()