5
. "launchpad.net/gocheck"
6
"launchpad.net/juju/go/cloudinit"
9
// TODO integration tests, but how?
15
func Test1(t *testing.T) {
19
var ctests = []struct {
22
option cloudinit.Option
25
"User", cloudinit.User("me")},
26
{"apt_upgrade: true\n",
27
"AptUpgrade", cloudinit.AptUpgrade(true)},
28
{"apt_update: true\n",
29
"AptUpdate", cloudinit.AptUpdate(true)},
30
{"apt_mirror: http://foo.com\n",
31
"AptMirror", cloudinit.AptMirror("http://foo.com")},
32
{"apt_mirror: true\n",
33
"AptPreserveSourcesList", cloudinit.AptPreserveSourcesList(true)},
34
{"apt_old_mirror: http://foo.com\n",
35
"AptOldMirror", cloudinit.AptOldMirror("http://foo.com")},
36
{"apt_sources:\n- source: keyName\n key: someKey\n",
37
"AptSources", cloudinit.AptSources(cloudinit.NewSource("keyName", "someKey"))},
38
{"apt_sources:\n- source: keyName\n keyid: someKey\n keyserver: foo.com\n",
39
"AptSources", cloudinit.AptSources(cloudinit.NewSourceWithKeyId("keyName", "someKey", "foo.com"))},
40
{"debconf_selections: true\n",
41
"DebConfSelections", cloudinit.DebConfSelections(true)},
42
{"packages:\n- juju\n- ubuntu\n",
43
"Packages", cloudinit.Packages("juju", "ubuntu")},
44
{"bootcmd:\n- ls > /dev\n- - ls\n - '>with space'\n",
45
"BootCmd", cloudinit.BootCmd(cloudinit.NewLiteralCommand("ls > /dev"), cloudinit.NewArgListCommand("ls", ">with space"))},
46
{"disable_ec2_metadata: true\n",
47
"DisableEC2Metadata", cloudinit.DisableEC2Metadata(true)},
48
{"final_message: goodbye\n",
49
"FinalMessage", cloudinit.FinalMessage("goodbye")},
51
"Locale", cloudinit.Locale("en_us")},
52
{"mounts:\n- - x\n - \"y\"\n- - z\n - w\n",
53
"Mounts", cloudinit.Mounts([][]string{{"x", "y"}, {"z", "w"}})},
54
{"output:\n all:\n stdout: '>foo'\n stderr: '|bar'\n",
55
"Output", cloudinit.Output(map[string]cloudinit.OutputSpec{"all": {">foo", "|bar"}})},
56
{"ssh_keys:\n- - rsa_private\n - key1data\n- - dsa_public\n - key2data\n",
57
"SSHKeys", cloudinit.SSHKeys([]cloudinit.Key{
58
{cloudinit.RSA | cloudinit.Private, "key1data"},
59
{cloudinit.DSA | cloudinit.Public, "key2data"},
61
{"disable_root: false\n",
62
"DisableRoot", cloudinit.DisableRoot(false)},
63
{"ssh_authorized_keys:\n- key1\n- key2\n",
64
"SSHAuthorizedKeys", cloudinit.SSHAuthorizedKeys("key1", "key2")},
67
const header = "#cloud-config\n"
69
func (S) TestOutput(c *C) {
70
for _, t := range ctests {
71
cfg := cloudinit.New()
73
data, err := cfg.Render()
75
c.Assert(data, NotNil)
76
c.Assert(string(data), Equals, header+t.expect, Bug("test %q output differs", t.name))
80
var atests = []struct {
83
options []cloudinit.Option
85
{"ssh_authorized_keys:\n- key1\n- key2\n- key3\n- key4\n",
88
cloudinit.SSHAuthorizedKeys("key1", "key2"),
89
cloudinit.SSHAuthorizedKeys("key3", "key4"),
92
{"apt_sources:\n- source: keyName\n keyid: someKey\n keyserver: foo.com\n- source: keyName\n key: someKey\n",
95
cloudinit.AptSources(cloudinit.NewSourceWithKeyId("keyName", "someKey", "foo.com")),
96
cloudinit.AptSources(cloudinit.NewSource("keyName", "someKey")),
101
func (S) TestAppend(c *C) {
102
for _, t := range atests {
103
cfg := cloudinit.New()
104
cfg.Set(t.options[0])
105
for _, o := range t.options[1:] {
108
data, err := cfg.Render()
110
c.Assert(data, NotNil)
111
c.Assert(string(data), Equals, header+t.expect, Bug("test %q output differs", t.name))
119
func ExampleConfig() {
120
cfg := cloudinit.New()
121
cfg.Set(cloudinit.Packages("juju", "ubuntu"))
122
data, err := cfg.Render()
124
fmt.Printf("render error: %v", err)
127
fmt.Printf("%s", data)