1aabacc769
This attempts to retrieve cloudconfigs from two sources: the meta-data service, and the user-data service. If only one cloudconfig is found, that is applied to the system. If both services return a cloudconfig, the two are merged into a single cloudconfig which is then applied to the system. Only a subset of parameters are merged (because the meta-data service currently only partially populates a cloudconfig). In the event of any conflicts, parameters in the user-data cloudconfig take precedence over those in the meta-data cloudconfig.
50 lines
975 B
Go
50 lines
975 B
Go
package initialize
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestParseHeaderCRLF(t *testing.T) {
|
|
configs := []string{
|
|
"#cloud-config\nfoo: bar",
|
|
"#cloud-config\r\nfoo: bar",
|
|
}
|
|
|
|
for i, config := range configs {
|
|
_, err := ParseUserData(config)
|
|
if err != nil {
|
|
t.Errorf("Failed parsing config %d: %v", i, err)
|
|
}
|
|
}
|
|
|
|
scripts := []string{
|
|
"#!bin/bash\necho foo",
|
|
"#!bin/bash\r\necho foo",
|
|
}
|
|
|
|
for i, script := range scripts {
|
|
_, err := ParseUserData(script)
|
|
if err != nil {
|
|
t.Errorf("Failed parsing script %d: %v", i, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestParseConfigCRLF(t *testing.T) {
|
|
contents := "#cloud-config\r\nhostname: foo\r\nssh_authorized_keys:\r\n - foobar\r\n"
|
|
ud, err := ParseUserData(contents)
|
|
if err != nil {
|
|
t.Fatalf("Failed parsing config: %v", err)
|
|
}
|
|
|
|
cfg := ud.(*CloudConfig)
|
|
|
|
if cfg.Hostname != "foo" {
|
|
t.Error("Failed parsing hostname from config")
|
|
}
|
|
|
|
if len(cfg.SSHAuthorizedKeys) != 1 {
|
|
t.Error("Parsed incorrect number of SSH keys")
|
|
}
|
|
}
|