@@ -242,20 +242,29 @@ func (s *migrateAgentEnvUUIDSuite) primeConfig(c *gc.C) {
242
242
func (s * migrateAgentEnvUUIDSuite ) removeEnvUUIDFromAgentConfig (c * gc.C ) {
243
243
// Read the file in as simple map[string]interface{} and delete
244
244
// the element, and write it back out again.
245
+
246
+ // First step, read the file contents.
245
247
filename := agent .ConfigPath (agent .DefaultDataDir , s .machine .Tag ())
246
248
data , err := ioutil .ReadFile (filename )
247
- c .Logf ("Data in:\n \n %s\n " , data )
248
249
c .Assert (err , jc .ErrorIsNil )
250
+ c .Logf ("Data in:\n \n %s\n " , data )
251
+
252
+ // Parse it into the map.
249
253
var content map [string ]interface {}
250
254
err = goyaml .Unmarshal (data , & content )
251
255
c .Assert (err , jc .ErrorIsNil )
256
+
257
+ // Remove the environment value, and marshal back into bytes.
252
258
delete (content , "environment" )
253
259
data , err = goyaml .Marshal (content )
254
260
c .Assert (err , jc .ErrorIsNil )
261
+
262
+ // Write the yaml back out remembering to add the format prefix.
255
263
data = append ([]byte ("# format 1.18\n " ), data ... )
256
264
c .Logf ("Data out:\n \n %s\n " , data )
257
265
err = ioutil .WriteFile (filename , data , 0644 )
258
266
c .Assert (err , jc .ErrorIsNil )
267
+
259
268
// Reset test attributes.
260
269
cfg , err := agent .ReadConfig (filename )
261
270
c .Assert (err , jc .ErrorIsNil )
0 commit comments