211
211
assertUserData(c, cloudConf, expected)
214
// TestCloudInitUserDataNoNetworkConfig tests that no network-interfaces, or
215
// related data, appear in user-data when no networkConfig is passed to
216
// CloudInitUserData.
217
func (s *UserDataSuite) TestCloudInitUserDataNoNetworkConfig(c *gc.C) {
218
instanceConfig, err := containertesting.MockMachineConfig("1/lxd/0")
219
c.Assert(err, jc.ErrorIsNil)
220
data, err := containerinit.CloudInitUserData(instanceConfig, nil)
221
c.Assert(err, jc.ErrorIsNil)
222
c.Assert(data, gc.NotNil)
224
// Extract the "#cloud-config" header and any lines from the "bootcmd"
225
// section up to (but not including) the "output" sections, to match
226
// against expected. We do not expect to find any, as we have not
227
// passed in a networkConfig.
228
// In this test we care about the networkConfig not all the /other/
229
// output that may be added by CloudInitUserData() in the future, which
230
// we cannot know about, so we do not check beyond "bootcmd".
231
var linesToMatch []string
233
for _, line := range strings.Split(string(data), "\n") {
234
if strings.HasPrefix(line, "#cloud-config") {
235
linesToMatch = append(linesToMatch, line)
239
if strings.HasPrefix(line, "bootcmd:") {
243
if strings.HasPrefix(line, "output:") && seenBootcmd {
248
linesToMatch = append(linesToMatch, line)
252
c.Assert(strings.Join(linesToMatch, "\n"), gc.Equals, "#cloud-config")
214
255
func (s *UserDataSuite) TestCloudInitUserDataFallbackConfig(c *gc.C) {
215
256
instanceConfig, err := containertesting.MockMachineConfig("1/lxd/0")
216
257
c.Assert(err, jc.ErrorIsNil)