cloudapi: test repository config conversion function
This commit is contained in:
parent
679028bb8e
commit
346486cd3f
1 changed files with 127 additions and 0 deletions
|
|
@ -116,3 +116,130 @@ func TestCollectRepos(t *testing.T) {
|
|||
|
||||
assert.Equal(pkgSetRepos, expectedPkgSetRepos)
|
||||
}
|
||||
|
||||
func TestRepoConfigConversion(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
type testCase struct {
|
||||
repo Repository
|
||||
repoConfig rpmmd.RepoConfig
|
||||
}
|
||||
|
||||
testCases := []testCase{
|
||||
{
|
||||
repo: Repository{
|
||||
Baseurl: common.StringToPtr("http://base.url"),
|
||||
CheckGpg: common.BoolToPtr(true),
|
||||
GpgKey: common.StringToPtr("some-kind-of-key"),
|
||||
IgnoreSsl: common.BoolToPtr(false),
|
||||
Metalink: nil,
|
||||
Mirrorlist: nil,
|
||||
Rhsm: false,
|
||||
PackageSets: nil,
|
||||
},
|
||||
repoConfig: rpmmd.RepoConfig{
|
||||
Name: "",
|
||||
BaseURL: "http://base.url",
|
||||
Metalink: "",
|
||||
MirrorList: "",
|
||||
GPGKey: "some-kind-of-key",
|
||||
CheckGPG: true,
|
||||
IgnoreSSL: false,
|
||||
MetadataExpire: "",
|
||||
RHSM: false,
|
||||
ImageTypeTags: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
repo: Repository{
|
||||
Baseurl: common.StringToPtr("http://base.url"),
|
||||
CheckGpg: nil,
|
||||
GpgKey: nil,
|
||||
IgnoreSsl: common.BoolToPtr(true),
|
||||
Metalink: common.StringToPtr("http://example.org/metalink"),
|
||||
Mirrorlist: common.StringToPtr("http://example.org/mirrorlist"),
|
||||
Rhsm: false,
|
||||
PackageSets: nil,
|
||||
},
|
||||
repoConfig: rpmmd.RepoConfig{
|
||||
Name: "",
|
||||
BaseURL: "http://base.url",
|
||||
Metalink: "", // since BaseURL is specified, MetaLink is not copied
|
||||
MirrorList: "", // since BaseURL is specified, MirrorList is not copied
|
||||
GPGKey: "",
|
||||
CheckGPG: false,
|
||||
IgnoreSSL: true,
|
||||
MetadataExpire: "",
|
||||
RHSM: false,
|
||||
ImageTypeTags: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
repo: Repository{
|
||||
Baseurl: nil,
|
||||
CheckGpg: nil,
|
||||
GpgKey: nil,
|
||||
IgnoreSsl: common.BoolToPtr(true),
|
||||
Metalink: common.StringToPtr("http://example.org/metalink"),
|
||||
Mirrorlist: common.StringToPtr("http://example.org/mirrorlist"),
|
||||
Rhsm: false,
|
||||
PackageSets: nil,
|
||||
},
|
||||
repoConfig: rpmmd.RepoConfig{
|
||||
Name: "",
|
||||
BaseURL: "",
|
||||
Metalink: "", // since MirrorList is specified, MetaLink is not copied
|
||||
MirrorList: "http://example.org/mirrorlist",
|
||||
GPGKey: "",
|
||||
CheckGPG: false,
|
||||
IgnoreSSL: true,
|
||||
MetadataExpire: "",
|
||||
RHSM: false,
|
||||
ImageTypeTags: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
repo: Repository{
|
||||
Baseurl: nil,
|
||||
CheckGpg: nil,
|
||||
GpgKey: nil,
|
||||
IgnoreSsl: common.BoolToPtr(true),
|
||||
Metalink: common.StringToPtr("http://example.org/metalink"),
|
||||
Mirrorlist: nil,
|
||||
Rhsm: true,
|
||||
PackageSets: nil,
|
||||
},
|
||||
repoConfig: rpmmd.RepoConfig{
|
||||
Name: "",
|
||||
BaseURL: "",
|
||||
Metalink: "http://example.org/metalink",
|
||||
MirrorList: "",
|
||||
GPGKey: "",
|
||||
CheckGPG: false,
|
||||
IgnoreSSL: true,
|
||||
MetadataExpire: "",
|
||||
RHSM: true,
|
||||
ImageTypeTags: nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for idx, tc := range testCases {
|
||||
rc, err := genRepoConfig(tc.repo)
|
||||
assert.NoError(err)
|
||||
assert.Equal(rc, &tc.repoConfig, "mismatch in test case %d", idx)
|
||||
}
|
||||
|
||||
// test error
|
||||
noURL := Repository{
|
||||
Baseurl: nil,
|
||||
CheckGpg: nil,
|
||||
GpgKey: nil,
|
||||
IgnoreSsl: nil,
|
||||
Metalink: nil,
|
||||
Mirrorlist: nil,
|
||||
Rhsm: true,
|
||||
PackageSets: nil,
|
||||
}
|
||||
_, err := genRepoConfig(noURL)
|
||||
assert.EqualError(err, HTTPError(ErrorInvalidRepository).Error())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue