Merge pull request #8 from bcwaldon/cloud-config-header

feat(serialization): Add #cloud-config header
This commit is contained in:
Brian Waldon 2014-03-12 17:12:25 -07:00
commit 6a6897831a
2 changed files with 17 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package cloudinit
import (
"fmt"
"log"
"launchpad.net/goyaml"
@ -26,11 +27,14 @@ func NewCloudConfig(contents []byte) (*CloudConfig, error) {
func (cc CloudConfig) String() string {
bytes, err := goyaml.Marshal(cc)
if err == nil {
return string(bytes)
} else {
if err != nil {
return ""
}
stringified := string(bytes)
stringified = fmt.Sprintf("#cloud-config\n%s", stringified)
return stringified
}
func ApplyCloudConfig(cfg CloudConfig, sshKeyName string) error {

View File

@ -1,6 +1,7 @@
package cloudinit
import (
"strings"
"testing"
)
@ -146,3 +147,12 @@ ssh_authorized_keys:
t.Error("Parsed incorrect number of SSH keys")
}
}
func TestCloudConfigSerializationHeader(t *testing.T) {
cfg, _ := NewCloudConfig([]byte{})
contents := cfg.String()
header := strings.SplitN(contents, "\n", 2)[0]
if header != "#cloud-config" {
t.Fatalf("Serialized config did not have expected header")
}
}