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
setOption func(cfg *cloudinit.Config)
27
func(cfg *cloudinit.Config) {
33
"apt_upgrade: true\n",
34
func(cfg *cloudinit.Config) {
35
cfg.SetAptUpgrade(true)
41
func(cfg *cloudinit.Config) {
42
cfg.SetAptUpdate(true)
47
"apt_mirror: http://foo.com\n",
48
func(cfg *cloudinit.Config) {
49
cfg.SetAptMirror("http://foo.com")
53
"AptPreserveSourcesList",
55
func(cfg *cloudinit.Config) {
56
cfg.SetAptPreserveSourcesList(true)
61
"debconf_selections: '# Force debconf priority to critical.\n\n debconf debconf/priority select critical\n\n'\n",
62
func(cfg *cloudinit.Config) {
63
cfg.SetDebconfSelections("# Force debconf priority to critical.\ndebconf debconf/priority select critical\n")
68
"disable_ec2_metadata: true\n",
69
func(cfg *cloudinit.Config) {
70
cfg.SetDisableEC2Metadata(true)
75
"final_message: goodbye\n",
76
func(cfg *cloudinit.Config) {
77
cfg.SetFinalMessage("goodbye")
83
func(cfg *cloudinit.Config) {
84
cfg.SetLocale("en_us")
89
"disable_root: false\n",
90
func(cfg *cloudinit.Config) {
91
cfg.SetDisableRoot(false)
96
"ssh_authorized_keys:\n- key1\n- key2\n",
97
func(cfg *cloudinit.Config) {
98
cfg.AddSSHAuthorizedKey("key1")
99
cfg.AddSSHAuthorizedKey("key2")
104
"ssh_keys:\n rsa_private: key1data\n rsa_public: key2data\n",
105
func(cfg *cloudinit.Config) {
106
cfg.AddSSHKey(cloudinit.RSAPrivate, "key1data")
107
cfg.AddSSHKey(cloudinit.RSAPublic, "key2data")
112
"ssh_keys:\n dsa_public: key1data\n dsa_private: key2data\n",
113
func(cfg *cloudinit.Config) {
114
cfg.AddSSHKey(cloudinit.DSAPublic, "key1data")
115
cfg.AddSSHKey(cloudinit.DSAPrivate, "key2data")
120
"output:\n all:\n - '>foo'\n - '|bar'\n",
121
func(cfg *cloudinit.Config) {
122
cfg.SetOutput("all", ">foo", "|bar")
127
"output:\n all: '>foo'\n",
128
func(cfg *cloudinit.Config) {
129
cfg.SetOutput(cloudinit.OutAll, ">foo", "")
134
"apt_sources:\n- source: keyName\n key: someKey\n",
135
func(cfg *cloudinit.Config) {
136
cfg.AddAptSource("keyName", "someKey")
141
"apt_sources:\n- source: keyName\n keyid: someKey\n keyserver: foo.com\n",
142
func(cfg *cloudinit.Config) {
143
cfg.AddAptSourceWithKeyId("keyName", "someKey", "foo.com")
148
"packages:\n- juju\n- ubuntu\n",
149
func(cfg *cloudinit.Config) {
150
cfg.AddPackage("juju")
151
cfg.AddPackage("ubuntu")
156
"bootcmd:\n- ls > /dev\n- - ls\n - '>with space'\n",
157
func(cfg *cloudinit.Config) {
158
cfg.AddBootCmd("ls > /dev")
159
cfg.AddBootCmdArgs("ls", ">with space")
164
"mounts:\n- - x\n - \"y\"\n- - z\n - w\n",
165
func(cfg *cloudinit.Config) {
166
cfg.AddMount("x", "y")
167
cfg.AddMount("z", "w")
172
const header = "#cloud-config\n"
174
func (S) TestOutput(c *C) {
175
for _, t := range ctests {
176
cfg := cloudinit.New()
178
data, err := cfg.Render()
180
c.Assert(data, NotNil)
181
c.Assert(string(data), Equals, header+t.expect, Bug("test %q output differs", t.name))
189
func ExampleConfig() {
190
cfg := cloudinit.New()
191
cfg.AddPackage("juju")
192
cfg.AddPackage("ubuntu")
193
data, err := cfg.Render()
195
fmt.Printf("render error: %v", err)
198
fmt.Printf("%s", data)