0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-16 21:56:37 -05:00

fix(test): TestConfigReloader, wait for trivy db download (#1543)

Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
This commit is contained in:
peusebiu 2023-07-06 14:17:49 +03:00 committed by GitHub
parent 0a04b2a4ed
commit 49e4d93f42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 6 deletions

View file

@ -300,6 +300,8 @@ func (c *Controller) LoadNewConfig(reloadCtx context.Context, config *config.Con
c.Config.Extensions = nil
}
c.InitCVEInfo()
c.StartBackgroundTasks(reloadCtx)
c.Log.Info().Interface("reloaded params", c.Config.Sanitize()).

View file

@ -1,3 +1,6 @@
//go:build search
// +build search
package cli_test
import (
@ -322,7 +325,7 @@ func TestConfigReloader(t *testing.T) {
"cve": {
"updateInterval": "24h",
"trivy": {
"DBRepository": "ghcr.io/aquasecurity/trivy-db"
"DBRepository": "unreachable/trivy/url1"
}
}
},
@ -367,7 +370,7 @@ func TestConfigReloader(t *testing.T) {
"cve": {
"updateInterval": "5h",
"trivy": {
"DBRepository": "ghcr.io/project-zot/trivy-db"
"DBRepository": "another/unreachable/trivy/url2"
}
}
}
@ -387,7 +390,12 @@ func TestConfigReloader(t *testing.T) {
So(err, ShouldBeNil)
// wait for config reload
time.Sleep(2 * time.Second)
time.Sleep(5 * time.Second)
found, err := test.ReadLogFileAndSearchString(logFile.Name(),
"Error downloading Trivy DB to destination dir", 30*time.Second)
So(err, ShouldBeNil)
So(found, ShouldBeTrue)
data, err := os.ReadFile(logFile.Name())
So(err, ShouldBeNil)
@ -397,7 +405,12 @@ func TestConfigReloader(t *testing.T) {
So(string(data), ShouldContainSubstring, "loaded new configuration settings")
So(string(data), ShouldContainSubstring, "\"UpdateInterval\":18000000000000")
So(string(data), ShouldContainSubstring, "\"Scrub\":null")
So(string(data), ShouldContainSubstring, "\"DBRepository\":\"ghcr.io/project-zot/trivy-db\"")
So(string(data), ShouldContainSubstring, "\"DBRepository\":\"another/unreachable/trivy/url2\"")
// matching log message when it errors out, test that indeed the download will try the second url
found, err = test.ReadLogFileAndSearchString(logFile.Name(),
"\"dbRepository\":\"another/unreachable/trivy/url2\",\"goroutine", 1*time.Minute)
So(err, ShouldBeNil)
So(found, ShouldBeTrue)
})
Convey("reload bad config", t, func(c C) {

View file

@ -497,9 +497,12 @@ func (scanner Scanner) updateDB(dbDir string) error {
registryOpts := fanalTypes.RegistryOptions{Insecure: false}
scanner.log.Debug().Str("dbDir", dbDir).Msg("Started downloading Trivy DB to destination dir")
err := operation.DownloadDB(ctx, "dev", dbDir, scanner.dbRepository, false, false, registryOpts)
if err != nil {
scanner.log.Error().Err(err).Str("dbDir", dbDir).Msg("Error downloading Trivy DB to destination dir")
scanner.log.Error().Err(err).Str("dbDir", dbDir).
Str("dbRepository", scanner.dbRepository).Msg("Error downloading Trivy DB to destination dir")
return err
}
@ -508,7 +511,8 @@ func (scanner Scanner) updateDB(dbDir string) error {
javadb.Init(dbDir, scanner.javaDBRepository, false, false, registryOpts.Insecure)
if err := javadb.Update(); err != nil {
scanner.log.Error().Err(err).Str("dbDir", dbDir).Msg("Error downloading Trivy Java DB to destination dir")
scanner.log.Error().Err(err).Str("dbDir", dbDir).
Str("javaDBRepository", scanner.javaDBRepository).Msg("Error downloading Trivy Java DB to destination dir")
return err
}