cloudapi: test new repository collection function
This commit is contained in:
parent
3320f2c57d
commit
2d0755b924
1 changed files with 93 additions and 0 deletions
|
|
@ -3,6 +3,9 @@ package v2
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/osbuild/osbuild-composer/internal/common"
|
||||||
|
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -23,3 +26,93 @@ func TestSplitExtension(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCollectRepos(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
// user repositories from request customizations
|
||||||
|
customRepos := []Repository{
|
||||||
|
{
|
||||||
|
Baseurl: common.StringToPtr("http://example.com/repoone"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Baseurl: common.StringToPtr("http://example.com/repotwo"),
|
||||||
|
PackageSets: &[]string{"should-be-ignored"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// repos from the image request (standard repos + package set repos)
|
||||||
|
irRepos := []Repository{
|
||||||
|
{
|
||||||
|
Baseurl: common.StringToPtr("http://example.com/baseos"), // empty field -> all package sets
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Baseurl: common.StringToPtr("http://example.com/appstream"), // empty field -> all package sets
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Baseurl: common.StringToPtr("http://example.com/baseos-rhel7"), // only build
|
||||||
|
PackageSets: &[]string{"build"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Baseurl: common.StringToPtr("http://example.com/extra-tools"), // build and archive
|
||||||
|
PackageSets: &[]string{"build", "archive"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Baseurl: common.StringToPtr("http://example.com/custom-os-stuff"), // blueprint -> merge with custom
|
||||||
|
PackageSets: &[]string{"blueprint"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedPkgSetRepos := map[string][]rpmmd.RepoConfig{
|
||||||
|
"build": {
|
||||||
|
{
|
||||||
|
BaseURL: "http://example.com/baseos-rhel7",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
BaseURL: "http://example.com/extra-tools",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"archive": {
|
||||||
|
{
|
||||||
|
BaseURL: "http://example.com/extra-tools",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"blueprint": {
|
||||||
|
{
|
||||||
|
BaseURL: "http://example.com/custom-os-stuff",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
BaseURL: "http://example.com/repoone",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
BaseURL: "http://example.com/repotwo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
payloadPkgSets := []string{"blueprint"}
|
||||||
|
|
||||||
|
baseRepos, pkgSetRepos, err := collectRepos(irRepos, customRepos, payloadPkgSets)
|
||||||
|
|
||||||
|
// check lengths
|
||||||
|
assert.NoError(err)
|
||||||
|
assert.Len(baseRepos, 2)
|
||||||
|
assert.Len(pkgSetRepos, 3)
|
||||||
|
|
||||||
|
// check tags in package set repo map
|
||||||
|
for _, tag := range []string{"blueprint", "build", "archive"} {
|
||||||
|
assert.Contains(pkgSetRepos, tag)
|
||||||
|
}
|
||||||
|
assert.NotContains(pkgSetRepos, "should-be-ignored")
|
||||||
|
|
||||||
|
// check URLs
|
||||||
|
baseRepoURLs := make([]string, len(baseRepos))
|
||||||
|
for idx, baseRepo := range baseRepos {
|
||||||
|
baseRepoURLs[idx] = baseRepo.BaseURL
|
||||||
|
}
|
||||||
|
for _, url := range []string{"http://example.com/baseos", "http://example.com/appstream"} {
|
||||||
|
assert.Contains(baseRepoURLs, url)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(pkgSetRepos, expectedPkgSetRepos)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue