ParseUserData: return nil on empty input string
This commit is contained in:
parent
231c0fa20b
commit
d4e048a1f4
@ -115,7 +115,7 @@ func main() {
|
||||
env := initialize.NewEnvironment("/", ds.ConfigRoot(), workspace, convertNetconf, sshKeyName, subs)
|
||||
|
||||
var ccm, ccu *initialize.CloudConfig
|
||||
var script system.Script
|
||||
var script *system.Script
|
||||
if ccm, err = initialize.ParseMetaData(string(metadataBytes)); err != nil {
|
||||
fmt.Printf("Failed to parse meta-data: %v\n", err)
|
||||
die()
|
||||
@ -128,7 +128,7 @@ func main() {
|
||||
case *initialize.CloudConfig:
|
||||
ccu = t
|
||||
case system.Script:
|
||||
script = t
|
||||
script = &t
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,7 +155,7 @@ func main() {
|
||||
}
|
||||
|
||||
if script != nil {
|
||||
if err = runScript(script, env); err != nil {
|
||||
if err = runScript(*script, env); err != nil {
|
||||
fmt.Printf("Failed to run script: %v\n", err)
|
||||
die()
|
||||
}
|
||||
|
@ -9,6 +9,9 @@ import (
|
||||
)
|
||||
|
||||
func ParseUserData(contents string) (interface{}, error) {
|
||||
if len(contents) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
header := strings.SplitN(contents, "\n", 2)[0]
|
||||
|
||||
// Explicitly trim the header so we can handle user-data from
|
||||
|
@ -47,3 +47,12 @@ func TestParseConfigCRLF(t *testing.T) {
|
||||
t.Error("Parsed incorrect number of SSH keys")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseConfigEmpty(t *testing.T) {
|
||||
i, e := ParseUserData(``)
|
||||
if i != nil {
|
||||
t.Error("ParseUserData of empty string returned non-nil unexpectedly")
|
||||
} else if e != nil {
|
||||
t.Error("ParseUserData of empty string returned error unexpectedly")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user