~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/cloudconfig/containerinit/container_userdata_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
211
211
        assertUserData(c, cloudConf, expected)
212
212
}
213
213
 
 
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)
 
223
 
 
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
 
232
        seenBootcmd := false
 
233
        for _, line := range strings.Split(string(data), "\n") {
 
234
                if strings.HasPrefix(line, "#cloud-config") {
 
235
                        linesToMatch = append(linesToMatch, line)
 
236
                        continue
 
237
                }
 
238
 
 
239
                if strings.HasPrefix(line, "bootcmd:") {
 
240
                        seenBootcmd = true
 
241
                }
 
242
 
 
243
                if strings.HasPrefix(line, "output:") && seenBootcmd {
 
244
                        break
 
245
                }
 
246
 
 
247
                if seenBootcmd {
 
248
                        linesToMatch = append(linesToMatch, line)
 
249
                }
 
250
        }
 
251
 
 
252
        c.Assert(strings.Join(linesToMatch, "\n"), gc.Equals, "#cloud-config")
 
253
}
 
254
 
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)