This repository has been archived by the owner on Jul 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 220
Adding filter options to chart-repo #658
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
05a2434
Adding filter options to chart-repo
gregsidelinger 7ae1031
Updating filter tests
gregsidelinger 57ce3c5
Moving filter logic to function
gregsidelinger b7bcef0
Update cmd/chart-repo/chart_repo.go
gregsidelinger 9a445e2
Update cmd/chart-repo/chart_repo.go
gregsidelinger c95b4f0
Minor filter updates
gregsidelinger 8f1f782
Adding glob matching to name filters
gregsidelinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,7 +183,7 @@ func Test_syncURLInvalidity(t *testing.T) { | |
dbSession := mockstore.NewMockSession(&m) | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
err := syncRepo(dbSession, "test", tt.repoURL, "") | ||
err := syncRepo(dbSession, "test", tt.repoURL, "", new(filters)) | ||
assert.ExistsErr(t, err, tt.name) | ||
}) | ||
} | ||
|
@@ -277,25 +277,98 @@ func Test_parseRepoIndex(t *testing.T) { | |
t.Run("valid", func(t *testing.T) { | ||
index, err := parseRepoIndex([]byte(validRepoIndexYAML)) | ||
assert.NoErr(t, err) | ||
assert.Equal(t, len(index.Entries), 2, "number of charts") | ||
assert.Equal(t, len(index.Entries), 3, "number of charts") | ||
assert.Equal(t, index.Entries["acs-engine-autoscaler"][0].GetName(), "acs-engine-autoscaler", "chart version populated") | ||
}) | ||
} | ||
|
||
func Test_chartsFromIndex(t *testing.T) { | ||
r := repo{Name: "test", URL: "http://testrepo.com"} | ||
index, _ := parseRepoIndex([]byte(validRepoIndexYAML)) | ||
charts := chartsFromIndex(index, r) | ||
assert.Equal(t, len(charts), 2, "number of charts") | ||
|
||
charts := chartsFromIndex(index, r, new(filters)) | ||
assert.Equal(t, len(charts), 3, "number of charts") | ||
indexWithDeprecated := validRepoIndexYAML + ` | ||
deprecated-chart: | ||
- name: deprecated-chart | ||
deprecated: true` | ||
index2, err := parseRepoIndex([]byte(indexWithDeprecated)) | ||
assert.NoErr(t, err) | ||
charts = chartsFromIndex(index2, r) | ||
assert.Equal(t, len(charts), 2, "number of charts") | ||
charts = chartsFromIndex(index2, r, new(filters)) | ||
assert.Equal(t, len(charts), 3, "number of charts") | ||
} | ||
|
||
func Test_chartsFromIndexFilterByName(t *testing.T) { | ||
r := repo{Name: "test", URL: "http://testrepo.com"} | ||
index, _ := parseRepoIndex([]byte(validRepoIndexYAML)) | ||
filter := new(filters) | ||
filter.Names = append(filter.Names, "wordpress") | ||
filter.Names = append(filter.Names, "not-found") | ||
charts := chartsFromIndex(index, r, filter) | ||
assert.Equal(t, len(charts), 1, "number of charts") | ||
} | ||
|
||
func Test_chartsFromIndexFilterByNameGlobbedSingleChar(t *testing.T) { | ||
r := repo{Name: "test", URL: "http://testrepo.com"} | ||
index, _ := parseRepoIndex([]byte(validRepoIndexYAML)) | ||
filter := new(filters) | ||
filter.Names = append(filter.Names, "word?ress") | ||
filter.Names = append(filter.Names, "not-found") | ||
charts := chartsFromIndex(index, r, filter) | ||
assert.Equal(t, len(charts), 1, "number of charts") | ||
} | ||
|
||
func Test_chartsFromIndexFilterByNameGlobbedWildcard(t *testing.T) { | ||
r := repo{Name: "test", URL: "http://testrepo.com"} | ||
index, _ := parseRepoIndex([]byte(validRepoIndexYAML)) | ||
filter := new(filters) | ||
filter.Names = append(filter.Names, "word*") | ||
filter.Names = append(filter.Names, "not-found") | ||
charts := chartsFromIndex(index, r, filter) | ||
assert.Equal(t, len(charts), 1, "number of charts") | ||
} | ||
|
||
func Test_chartsFromIndexFilterByAnnotationWithValue(t *testing.T) { | ||
r := repo{Name: "test", URL: "http://testrepo.com"} | ||
index, _ := parseRepoIndex([]byte(validRepoIndexYAML)) | ||
filter := new(filters) | ||
filter.Annotations = make(map[string]string) | ||
filter.Annotations["sync"] = "true" | ||
filter.Annotations["not-found"] = "missing" | ||
charts := chartsFromIndex(index, r, filter) | ||
assert.Equal(t, len(charts), 1, "number of charts") | ||
} | ||
|
||
func Test_chartsFromIndexFilterByAnnotation(t *testing.T) { | ||
r := repo{Name: "test", URL: "http://testrepo.com"} | ||
index, _ := parseRepoIndex([]byte(validRepoIndexYAML)) | ||
// filter on annotation | ||
filter := new(filters) | ||
filter.Annotations = make(map[string]string) | ||
filter.Annotations["sync-by-name-only"] = "" | ||
charts := chartsFromIndex(index, r, filter) | ||
assert.Equal(t, len(charts), 1, "number of charts") | ||
} | ||
|
||
func Test_chartsFromIndexFilterByAnnotationDuplicateMatches(t *testing.T) { | ||
r := repo{Name: "test", URL: "http://testrepo.com"} | ||
index, _ := parseRepoIndex([]byte(validRepoIndexYAML)) | ||
filter := new(filters) | ||
filter.Annotations = make(map[string]string) | ||
filter.Annotations["sync"] = "true" | ||
filter.Annotations["sync-by-name-only"] = "" | ||
charts := chartsFromIndex(index, r, filter) | ||
assert.Equal(t, len(charts), 1, "number of charts") | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's add a test for both an annotation and name filter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
func Test_chartsFromIndexFilterByAnnotationAndName(t *testing.T) { | ||
r := repo{Name: "test", URL: "http://testrepo.com"} | ||
index, _ := parseRepoIndex([]byte(validRepoIndexYAML)) | ||
filter := new(filters) | ||
filter.Annotations = make(map[string]string) | ||
filter.Annotations["sync"] = "true" | ||
filter.Names = append(filter.Names, "wordpress") | ||
charts := chartsFromIndex(index, r, filter) | ||
assert.Equal(t, len(charts), 1, "number of charts") | ||
} | ||
|
||
func Test_newChart(t *testing.T) { | ||
|
@@ -316,7 +389,7 @@ func Test_importCharts(t *testing.T) { | |
m.On("RemoveAll", mock.Anything) | ||
dbSession := mockstore.NewMockSession(m) | ||
index, _ := parseRepoIndex([]byte(validRepoIndexYAML)) | ||
charts := chartsFromIndex(index, repo{Name: "test", URL: "http://testrepo.com"}) | ||
charts := chartsFromIndex(index, repo{Name: "test", URL: "http://testrepo.com"}, new(filters)) | ||
importCharts(dbSession, charts) | ||
|
||
m.AssertExpectations(t) | ||
|
@@ -357,7 +430,7 @@ func Test_fetchAndImportIcon(t *testing.T) { | |
}) | ||
|
||
index, _ := parseRepoIndex([]byte(validRepoIndexYAML)) | ||
charts := chartsFromIndex(index, repo{Name: "test", URL: "http://testrepo.com"}) | ||
charts := chartsFromIndex(index, repo{Name: "test", URL: "http://testrepo.com"}, new(filters)) | ||
|
||
t.Run("failed download", func(t *testing.T) { | ||
netClient = &badHTTPClient{} | ||
|
@@ -402,7 +475,7 @@ func Test_fetchAndImportIcon(t *testing.T) { | |
|
||
func Test_fetchAndImportFiles(t *testing.T) { | ||
index, _ := parseRepoIndex([]byte(validRepoIndexYAML)) | ||
charts := chartsFromIndex(index, repo{Name: "test", URL: "http://testrepo.com", AuthorizationHeader: "Bearer ThisSecretAccessTokenAuthenticatesTheClient1s"}) | ||
charts := chartsFromIndex(index, repo{Name: "test", URL: "http://testrepo.com", AuthorizationHeader: "Bearer ThisSecretAccessTokenAuthenticatesTheClient1s"}, new(filters)) | ||
cv := charts[0].ChartVersions[0] | ||
|
||
t.Run("http error", func(t *testing.T) { | ||
|
@@ -622,7 +695,7 @@ func Test_emptyChartRepo(t *testing.T) { | |
m := mock.Mock{} | ||
m.On("One", &repoCheck{}).Return(nil) | ||
dbSession := mockstore.NewMockSession(&m) | ||
err := syncRepo(dbSession, "testRepo", "https://my.examplerepo.com", "") | ||
err := syncRepo(dbSession, "testRepo", "https://my.examplerepo.com", "", new(filters)) | ||
assert.ExistsErr(t, err, "Failed Request") | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the expectation here that it only needs to match one of the annotations and not all of the annotations? I would have assumed that all the annotations need to match for the entry to be selected (I believe this is also how
kubectl
label filters work).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point I did not think about that. My intend was if any of them matched it synced. That is actually how I just rewrote the code as a function.