From 2eada735bc2f691b5c532143f389b2cf6a29f637 Mon Sep 17 00:00:00 2001 From: FengyunPan2 Date: Fri, 22 Jun 2018 15:05:58 +0800 Subject: [PATCH] Refresh all the repos Currently if config file have a bad repo and some right repos, monocualr-api don't get charts from repos and no error message to user. We should try all the repos. --- src/api/data/cache/auto_refresher_test.go | 2 +- src/api/data/cache/cache.go | 6 +++++- src/api/data/cache/cache_test.go | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/api/data/cache/auto_refresher_test.go b/src/api/data/cache/auto_refresher_test.go index 86fd8fb4b..1218c4cdc 100644 --- a/src/api/data/cache/auto_refresher_test.go +++ b/src/api/data/cache/auto_refresher_test.go @@ -35,5 +35,5 @@ func TestNewRefreshDataError(t *testing.T) { job := NewRefreshChartsData(chartsImplementation, freshness, "test-run", true) assert.Equal(t, job.FirstRun(), true, "First run") err := job.Do() - assert.ExistsErr(t, err, "Error executing refresh") + assert.NoErr(t, err) } diff --git a/src/api/data/cache/cache.go b/src/api/data/cache/cache.go index 51bda87cd..4ae79c161 100644 --- a/src/api/data/cache/cache.go +++ b/src/api/data/cache/cache.go @@ -240,7 +240,11 @@ func (c *cachedCharts) Refresh() error { for _, repo := range repos { charts, err := repohelper.GetChartsFromRepoIndexFile(repo) if err != nil { - return err + log.WithFields(log.Fields{ + "repo": repo, + "error": err, + }).Error("error on refresh charts from repo") + continue } // 3 - Process elements in index diff --git a/src/api/data/cache/cache_test.go b/src/api/data/cache/cache_test.go index 5d0d32722..7908109a5 100644 --- a/src/api/data/cache/cache_test.go +++ b/src/api/data/cache/cache_test.go @@ -180,7 +180,10 @@ func TestCachedChartsRefreshErrorPropagation(t *testing.T) { chImplementation := NewCachedCharts(models.NewMockSession(models.MockDBConfig{})) models.MockRepos = tt.repos err := chImplementation.Refresh() - assert.ExistsErr(t, err, tt.name) + assert.NoErr(t, err) + allCharts, err := chImplementation.All() + assert.NoErr(t, err) + assert.True(t, len(allCharts) == 0, "empty charts slice") }) } }