shared: Allow empty URL

Signed-off-by: Thomas Hipp <thomas.hipp@canonical.com>
This commit is contained in:
Thomas Hipp 2018-03-01 09:03:03 +01:00
parent b6c1538356
commit c9b245a820
No known key found for this signature in database
GPG Key ID: 993408D1137B7D51
2 changed files with 18 additions and 19 deletions

View File

@ -32,7 +32,7 @@ type DefinitionImage struct {
// A DefinitionSource specifies the download type and location
type DefinitionSource struct {
Downloader string `yaml:"downloader"`
URL string `yaml:"url"`
URL string `yaml:"url,omitempty"`
Keys []string `yaml:"keys,omitempty"`
Keyserver string `yaml:"keyserver,omitempty"`
Variant string `yaml:"variant,omitempty"`
@ -122,10 +122,6 @@ func ValidateDefinition(def Definition) error {
return fmt.Errorf("source.downloader must be one of %v", validDownloaders)
}
if strings.TrimSpace(def.Source.URL) == "" {
return errors.New("source.url may not be empty")
}
validManagers := []string{
"apk",
"apt",

View File

@ -65,6 +65,23 @@ func TestValidateDefinition(t *testing.T) {
"",
false,
},
{
"valid Defintion without source.url",
Definition{
Image: DefinitionImage{
Distribution: "ubuntu",
Release: "artful",
},
Source: DefinitionSource{
Downloader: "debootstrap",
},
Packages: DefinitionPackages{
Manager: "apt",
},
},
"",
false,
},
{
"empty image.distribution",
Definition{},
@ -85,20 +102,6 @@ func TestValidateDefinition(t *testing.T) {
"source.downloader must be one of .+",
true,
},
{
"empty source.url",
Definition{
Image: DefinitionImage{
Distribution: "ubuntu",
Release: "artful",
},
Source: DefinitionSource{
Downloader: "debootstrap",
},
},
"source.url may not be empty",
true,
},
{
"invalid package.manager",
Definition{