~dstroppa/juju-core/joyent-provider-storage

« back to all changes in this revision

Viewing changes to cloudinit/cloudinit_test.go

  • Committer: Daniele Stroppa
  • Date: 2014-01-08 15:58:10 UTC
  • mfrom: (1953.1.231 juju-core)
  • Revision ID: daniele.stroppa@joyent.com-20140108155810-xecbwrqkb5i0fyoe
Merging trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
        gc "launchpad.net/gocheck"
11
11
 
12
12
        "launchpad.net/juju-core/cloudinit"
 
13
        "launchpad.net/juju-core/testing/testbase"
 
14
        sshtesting "launchpad.net/juju-core/utils/ssh/testing"
13
15
)
14
16
 
15
17
// TODO integration tests, but how?
16
18
 
17
 
type S struct{}
 
19
type S struct {
 
20
        testbase.LoggingSuite
 
21
}
18
22
 
19
23
var _ = gc.Suite(S{})
20
24
 
106
110
        },
107
111
        {
108
112
                "SSHAuthorizedKeys",
109
 
                "ssh_authorized_keys:\n- key1\n- key2\n",
 
113
                fmt.Sprintf(
 
114
                        "ssh_authorized_keys:\n- %s\n  Juju:user@host\n- %s\n  Juju:another@host\n",
 
115
                        sshtesting.ValidKeyOne.Key, sshtesting.ValidKeyTwo.Key),
110
116
                func(cfg *cloudinit.Config) {
111
 
                        cfg.AddSSHAuthorizedKeys("key1")
112
 
                        cfg.AddSSHAuthorizedKeys("key2")
 
117
                        cfg.AddSSHAuthorizedKeys(sshtesting.ValidKeyOne.Key + " Juju:user@host")
 
118
                        cfg.AddSSHAuthorizedKeys(sshtesting.ValidKeyTwo.Key + " another@host")
113
119
                },
114
120
        },
115
121
        {
116
122
                "SSHAuthorizedKeys",
117
 
                "ssh_authorized_keys:\n- key1\n- key2\n- key3\n",
 
123
                fmt.Sprintf(
 
124
                        "ssh_authorized_keys:\n- %s\n  Juju:sshkey\n- %s\n  Juju:user@host\n- %s\n  Juju:another@host\n",
 
125
                        sshtesting.ValidKeyOne.Key, sshtesting.ValidKeyTwo.Key, sshtesting.ValidKeyThree.Key),
118
126
                func(cfg *cloudinit.Config) {
119
 
                        cfg.AddSSHAuthorizedKeys("#command\nkey1")
120
 
                        cfg.AddSSHAuthorizedKeys("key2\n# comment\n\nkey3\n")
 
127
                        cfg.AddSSHAuthorizedKeys("#command\n" + sshtesting.ValidKeyOne.Key)
 
128
                        cfg.AddSSHAuthorizedKeys(
 
129
                                sshtesting.ValidKeyTwo.Key + " user@host\n# comment\n\n" +
 
130
                                        sshtesting.ValidKeyThree.Key + " another@host")
121
131
                        cfg.AddSSHAuthorizedKeys("")
122
132
                },
123
133
        },
234
244
const (
235
245
        header          = "#cloud-config\n"
236
246
        addFileExpected = `runcmd:
237
 
- install -m 644 /dev/null '/etc/apt/apt.conf.d/99proxy'
 
247
- install -D -m 644 /dev/null '/etc/apt/apt.conf.d/99proxy'
238
248
- printf '%s\n' '"Acquire::http::Proxy "http://10.0.3.1:3142";' > '/etc/apt/apt.conf.d/99proxy'
239
249
`
240
250
)
269
279
        c.Assert(cfg.Packages(), gc.DeepEquals, []string{"a b c", "d!"})
270
280
}
271
281
 
 
282
func (S) TestSetOutput(c *gc.C) {
 
283
        type test struct {
 
284
                kind   cloudinit.OutputKind
 
285
                stdout string
 
286
                stderr string
 
287
        }
 
288
        tests := []test{{
 
289
                cloudinit.OutAll, "a", "",
 
290
        }, {
 
291
                cloudinit.OutAll, "", "b",
 
292
        }, {
 
293
                cloudinit.OutInit, "a", "b",
 
294
        }, {
 
295
                cloudinit.OutAll, "a", "b",
 
296
        }, {
 
297
                cloudinit.OutAll, "", "",
 
298
        }}
 
299
 
 
300
        cfg := cloudinit.New()
 
301
        stdout, stderr := cfg.Output(cloudinit.OutAll)
 
302
        c.Assert(stdout, gc.Equals, "")
 
303
        c.Assert(stderr, gc.Equals, "")
 
304
        for i, t := range tests {
 
305
                c.Logf("test %d: %+v", i, t)
 
306
                cfg.SetOutput(t.kind, t.stdout, t.stderr)
 
307
                stdout, stderr = cfg.Output(t.kind)
 
308
                c.Assert(stdout, gc.Equals, t.stdout)
 
309
                c.Assert(stderr, gc.Equals, t.stderr)
 
310
        }
 
311
}
 
312
 
272
313
//#cloud-config
273
314
//packages:
274
315
//- juju