fix some tests and some config behavior to prevent null dereference errors and incorrect precedence between iso checksum and iso checksum url
This commit is contained in:
parent
e85bac737b
commit
d6d4eb2087
|
@ -58,6 +58,11 @@ func (c *ISOConfig) Prepare(ctx *interpolate.Context) (warnings []string, errs [
|
|||
}
|
||||
|
||||
if c.ISOChecksumURL != "" {
|
||||
if c.ISOChecksum != "" {
|
||||
warnings = append(warnings, "You have provided both an "+
|
||||
"iso_checksum and an iso_checksum_url. Discarding the "+
|
||||
"iso_checksum_url and using the checksum.")
|
||||
} else {
|
||||
if strings.HasSuffix(strings.ToLower(c.ISOChecksumURL), ".iso") {
|
||||
errs = append(errs, fmt.Errorf("Error parsing checksum:"+
|
||||
" .iso is not a valid checksum extension"))
|
||||
|
@ -66,6 +71,7 @@ func (c *ISOConfig) Prepare(ctx *interpolate.Context) (warnings []string, errs [
|
|||
c.ISOChecksumType = "file"
|
||||
c.ISOChecksum = c.ISOChecksumURL
|
||||
}
|
||||
}
|
||||
|
||||
if c.ISOChecksum == "" {
|
||||
errs = append(errs, fmt.Errorf("A checksum must be specified"))
|
||||
|
@ -86,12 +92,13 @@ func (c *ISOConfig) Prepare(ctx *interpolate.Context) (warnings []string, errs [
|
|||
Getters: getter.Getters,
|
||||
}
|
||||
cksum, err := gc.ChecksumFromFile(c.ISOChecksumURL, u)
|
||||
if err != nil {
|
||||
if cksum == nil || err != nil {
|
||||
errs = append(errs, fmt.Errorf("Couldn't extract checksum from checksum file"))
|
||||
}
|
||||
} else {
|
||||
c.ISOChecksumType = cksum.Type
|
||||
c.ISOChecksum = hex.EncodeToString(cksum.Value)
|
||||
}
|
||||
}
|
||||
|
||||
return warnings, errs
|
||||
}
|
||||
|
|
|
@ -75,11 +75,16 @@ func TestISOConfigPrepare_ISOChecksum(t *testing.T) {
|
|||
func TestISOConfigPrepare_ISOChecksumURLBad(t *testing.T) {
|
||||
i := testISOConfig()
|
||||
i.ISOChecksumURL = "file:///not_read"
|
||||
i.ISOChecksum = "shouldoverride"
|
||||
|
||||
// Test ISOChecksum overrides url
|
||||
warns, err := i.Prepare(nil)
|
||||
if len(warns) > 0 && len(err) > 0 {
|
||||
t.Fatalf("bad: %#v, %#v", warns, err)
|
||||
if len(warns) != 1 {
|
||||
t.Fatalf("Bad: should have warned because both checksum and " +
|
||||
"checksumURL are set.")
|
||||
}
|
||||
if len(err) > 0 {
|
||||
t.Fatalf("Bad; should have warned but not errored.")
|
||||
}
|
||||
|
||||
// Test that we won't try to read an iso into memory because of a user
|
||||
|
|
Loading…
Reference in New Issue