tests: Fix tests

Signed-off-by: Thomas Hipp <thomas.hipp@canonical.com>
This commit is contained in:
Thomas Hipp 2018-03-16 13:35:04 +01:00
parent dd35a5830b
commit 02148a5918
No known key found for this signature in database
GPG Key ID: 993408D1137B7D51
2 changed files with 18 additions and 3 deletions

View File

@ -19,11 +19,17 @@ var lxdDef = shared.Definition{
Description: "{{ image.distribution|capfirst }} {{ image. release }}",
Distribution: "ubuntu",
Release: "17.10",
Architecture: "amd64",
Architecture: "x86_64",
Expiry: "30d",
Name: "{{ image.distribution|lower }}-{{ image.release }}-{{ image.architecture }}-{{ image.serial }}",
Serial: "testing",
},
Source: shared.DefinitionSource{
Downloader: "debootstrap",
},
Packages: shared.DefinitionPackages{
Manager: "apt",
},
}
func setupLXD(t *testing.T) *LXDImage {
@ -52,6 +58,14 @@ func setupLXD(t *testing.T) *LXDImage {
t.Fatal("lxdDef and image.definition are not equal")
}
lxdDef.SetDefaults()
err = lxdDef.Validate()
if err != nil {
teardownLXD(t)
t.Fatalf("Failed to validate image: %s", err)
}
return image
}

View File

@ -11,7 +11,7 @@ import (
func TestSetDefinitionDefaults(t *testing.T) {
def := Definition{}
SetDefinitionDefaults(&def)
def.SetDefaults()
uname, _ := shared.Uname()
@ -187,7 +187,8 @@ func TestValidateDefinition(t *testing.T) {
for i, tt := range tests {
log.Printf("Running test #%d: %s", i, tt.name)
err := ValidateDefinition(tt.definition)
tt.definition.SetDefaults()
err := tt.definition.Validate()
if !tt.shouldFail && err != nil {
t.Fatalf("Validation failed: %s", err)
} else if tt.shouldFail {