Skip to content

Commit

Permalink
Align testsuite to use multiple HTTP subsections
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessOne91 committed Sep 26, 2024
1 parent 5f59e3d commit a140ae4
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 61 deletions.
32 changes: 16 additions & 16 deletions cmd/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ func TestParseConfig(t *testing.T) {
Type: "file",
Path: "/srv/mirror",
},
HTTP: []get.HTTPRepoConfig{
{
URL: "http://test/SLE-Product-SLES15-SP5-Pool/",
Archs: []string{"x86_64", "aarch64", "s390x"},
},
{
URL: "http://test/SLE-Product-SLES15-SP5-Updates/",
Archs: []string{"x86_64", "aarch64"},
HTTP: get.HTTP{
Repositories: []get.HTTPReposConfig{
{
URLs: []string{"http://test/SLE-Product-SLES15-SP5-Pool/", "http://test/SLE-Product-SLES15-SP5-Updates/"},
Archs: []string{"x86_64", "aarch64", "s390x"},
},
{
URLs: []string{"http://test/SLE-Product-SLES15-SP6-Pool/", "http://test/SLE-Product-SLES15-SP6-Updates/"},
Archs: []string{"x86_64", "aarch64"},
},
},
},
},
Expand Down Expand Up @@ -74,14 +76,12 @@ func TestParseConfig(t *testing.T) {
Type: "memory",
Path: "/srv/mirror",
},
HTTP: []get.HTTPRepoConfig{
{
URL: "http://test/SLE-Product-SLES15-SP5-Pool/",
Archs: []string{"x86_64", "aarch64", "s390x"},
},
{
URL: "http://test/SLE-Product-SLES15-SP5-Updates/",
Archs: []string{"x86_64", "aarch64"},
HTTP: get.HTTP{
Repositories: []get.HTTPReposConfig{
{
URLs: []string{"http://test/SLE-Product-SLES15-SP5-Pool/", "http://test/SLE-Product-SLES15-SP5-Updates/"},
Archs: []string{"x86_64", "aarch64", "s390x"},
},
},
},
},
Expand Down
9 changes: 5 additions & 4 deletions cmd/testdata/invalid_storage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ storage:
path: /srv/mirror

http:
- url: http://test/SLE-Product-SLES15-SP5-Pool/
archs: [x86_64, aarch64, s390x]
- url: http://test/SLE-Product-SLES15-SP5-Updates/
archs: [x86_64, aarch64]
repositories:
- urls:
- http://test/SLE-Product-SLES15-SP5-Pool/
- http://test/SLE-Product-SLES15-SP5-Updates/
archs: [x86_64, aarch64, s390x]
13 changes: 9 additions & 4 deletions cmd/testdata/valid_http_repos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ storage:
path: /srv/mirror

http:
- url: http://test/SLE-Product-SLES15-SP5-Pool/
archs: [x86_64, aarch64, s390x]
- url: http://test/SLE-Product-SLES15-SP5-Updates/
archs: [x86_64, aarch64]
repositories:
- urls:
- http://test/SLE-Product-SLES15-SP5-Pool/
- http://test/SLE-Product-SLES15-SP5-Updates/
archs: [x86_64, aarch64, s390x]
- urls:
- http://test/SLE-Product-SLES15-SP6-Pool/
- http://test/SLE-Product-SLES15-SP6-Updates/
archs: [x86_64, aarch64]
8 changes: 4 additions & 4 deletions cmd/testdata/valid_scc_repos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ scc:
password: pass
repositories:
- names:
- SLE-Manager-Tools15-Pool
- SLE-Manager-Tools15-Updates
- SLE-Manager-Tools15-Pool
- SLE-Manager-Tools15-Updates
archs: [x86_64, aarch64, s390x]
- names:
- SLE-Product-SLES15-SP5-Pool
- SLE-Product-SLES15-SP5-Updates
- SLE-Product-SLES15-SP5-Pool
- SLE-Product-SLES15-SP5-Updates
archs: [x86_64, s390x]
148 changes: 115 additions & 33 deletions get/scc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,86 +24,168 @@ func TestSCCToHTTPConfigs(t *testing.T) {
})

http.HandleFunc("/connect/organizations/repositories2", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Link", "")
w.Header().Set("Link", "<http://localhost:8080/connect/organizations/repositories3>; rel=\"next\"")
fmt.Fprintf(w, "[{\"url\" : \"http://whatever/SLES15-SP5-Updates\", \"name\" : \"SLES15-SP5-Updates\", \"description\" : \"x86_64 aarch64 s390x ppc64le\"}]")
})

http.HandleFunc("/connect/organizations/repositories3", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Link", "")
fmt.Fprintf(w, "[{\"url\" : \"http://whatever/SLES15-SP6-Pool\", \"name\" : \"SLES15-SP6-Pool\", \"description\" : \"x86_64 aarch64\"}]")
})

tests := []struct {
name string
user string
pass string
names []string
archs []string
want []HTTPRepoConfig
wantErr bool
name string
user string
pass string
sccInput []SCCReposConfig
want []HTTPReposConfig
wantErr bool
}{
{
"One name and no matching arch", "user", "pass",
[]string{"SLES15-SP5-Pool"}, []string{"s390x"},
[]HTTPRepoConfig{},
[]SCCReposConfig{
{[]string{"SLES15-SP5-Pool"}, []string{"s390x"}},
},
[]HTTPReposConfig{},
false,
},
{
"One name and one matching arch", "user", "pass",
[]string{"SLES15-SP5-Pool"}, []string{"x86_64"},
[]HTTPRepoConfig{
{URL: "http://whatever/SLES15-SP5-Pool", Archs: []string{"x86_64"}},
[]SCCReposConfig{
{[]string{"SLES15-SP5-Pool"}, []string{"x86_64"}},
},
[]HTTPReposConfig{
{
URLs: []string{"http://whatever/SLES15-SP5-Pool"},
Archs: []string{"x86_64"},
},
},
false,
},
{
"One name and multiple matching archs", "user", "pass",
[]string{"SLES15-SP5-Pool"}, []string{"aarch64", "i586"},
[]HTTPRepoConfig{
{URL: "http://whatever/SLES15-SP5-Pool", Archs: []string{"aarch64", "i586"}},
[]SCCReposConfig{
{[]string{"SLES15-SP5-Pool"}, []string{"aarch64", "i586"}},
},
[]HTTPReposConfig{
{
URLs: []string{"http://whatever/SLES15-SP5-Pool"},
Archs: []string{"aarch64", "i586"},
},
},
false,
},
{
"Multiple names and no matching archs", "user", "pass",
[]string{"SLES15-SP5-Pool", "SLES15-SP5-Updates"}, []string{"src"},
[]HTTPRepoConfig{},
[]SCCReposConfig{
{[]string{"SLES15-SP5-Pool", "SLES15-SP5-Updates"}, []string{"src"}},
},
[]HTTPReposConfig{},
false,
},
{
"Multiple names and multiple matching archs", "user", "pass",
[]string{"SLES15-SP5-Pool", "SLES15-SP5-Updates"}, []string{"x86_64", "aarch64"},
[]HTTPRepoConfig{
{URL: "http://whatever/SLES15-SP5-Pool", Archs: []string{"x86_64", "aarch64"}},
{URL: "http://whatever/SLES15-SP5-Updates", Archs: []string{"x86_64", "aarch64"}},
[]SCCReposConfig{
{[]string{"SLES15-SP5-Pool", "SLES15-SP5-Updates"}, []string{"x86_64", "aarch64"}},
},
[]HTTPReposConfig{
{
URLs: []string{"http://whatever/SLES15-SP5-Pool", "http://whatever/SLES15-SP5-Updates"},
Archs: []string{"x86_64", "aarch64"},
},
},
false,
},
{
"Multiple configs and no matching archs", "user", "pass",
[]SCCReposConfig{
{[]string{"SLES15-SP5-Pool", "SLES15-SP5-Updates"}, []string{"src"}},
{[]string{"SLES15-SP6-Pool"}, []string{"s390x"}},
},
[]HTTPReposConfig{},
false,
},
{
"Multiple configs and one matching arch in the 2nd", "user", "pass",
[]SCCReposConfig{
{[]string{"SLES15-SP5-Pool", "SLES15-SP5-Updates"}, []string{"src"}},
{[]string{"SLES15-SP6-Pool"}, []string{"x86_64"}},
},
[]HTTPReposConfig{
{
URLs: []string{"http://whatever/SLES15-SP6-Pool"},
Archs: []string{"x86_64"},
},
},
false,
},
{
"Multiple configs and multiple matching archs", "user", "pass",
[]SCCReposConfig{
{[]string{"SLES15-SP5-Pool", "SLES15-SP5-Updates"}, []string{"x86_64"}},
{[]string{"SLES15-SP6-Pool"}, []string{"x86_64"}},
},
[]HTTPReposConfig{
{
URLs: []string{"http://whatever/SLES15-SP5-Pool", "http://whatever/SLES15-SP5-Updates"},
Archs: []string{"x86_64"},
},
{
URLs: []string{"http://whatever/SLES15-SP6-Pool"},
Archs: []string{"x86_64"},
},
},
false,
},
{
"Multiple configs and partially matching archs", "user", "pass",
[]SCCReposConfig{
{[]string{"SLES15-SP5-Pool", "SLES15-SP5-Updates"}, []string{"s390x"}},
{[]string{"SLES15-SP6-Pool"}, []string{"x86_64"}},
},
[]HTTPReposConfig{
{
URLs: []string{"http://whatever/SLES15-SP5-Updates"},
Archs: []string{"s390x"},
},
{
URLs: []string{"http://whatever/SLES15-SP6-Pool"},
Archs: []string{"x86_64"},
},
},
false,
},
{
"Invalid user", "thiswillfail", "pass",
[]string{"SLES15-SP5-Pool"}, []string{"x86_64"},
[]HTTPRepoConfig{},
[]SCCReposConfig{
{[]string{"SLES15-SP5-Pool"}, []string{"x86_64"}},
},
[]HTTPReposConfig{},
true,
},
{
"Invalid password", "user", "thiswillfail",
[]string{"SLES15-SP5-Pool"}, []string{"x86_64"},
[]HTTPRepoConfig{},
[]SCCReposConfig{
{[]string{"SLES15-SP5-Pool"}, []string{"x86_64"}},
},
[]HTTPReposConfig{},
true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
httpConfigs, err := SCCToHTTPConfigs("http://localhost:8080", tt.user, tt.pass, []SCCReposConfig{
{
Names: tt.names,
Archs: tt.archs,
},
})
httpConfigs, err := SCCToHTTPConfigs("http://localhost:8080", tt.user, tt.pass, tt.sccInput)

fmt.Println(httpConfigs)
assert.EqualValues(t, tt.wantErr, (err != nil))
assert.Equal(t, len(tt.want), len(httpConfigs))

for i := range httpConfigs {
wantConfig := tt.want[i]
gotConfig := httpConfigs[i]

assert.EqualValues(t, wantConfig.URL, gotConfig.URL)
assert.ElementsMatch(t, wantConfig.URLs, gotConfig.URLs)
assert.ElementsMatch(t, wantConfig.Archs, gotConfig.Archs)
}
})
Expand Down

0 comments on commit a140ae4

Please sign in to comment.