launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #15457
[Merge] lp:~rvb/juju-core/cleanup-tempfile into lp:~maas-maintainers/juju-core/maas-provider-skeleton
Raphaël Badin has proposed merging lp:~rvb/juju-core/cleanup-tempfile into lp:~maas-maintainers/juju-core/maas-provider-skeleton.
Commit message:
Use c.Mkdir() in createTempFile() to get the temporary files cleaned up at the end of the test.
Requested reviews:
MAAS Maintainers (maas-maintainers)
For more details, see:
https://code.launchpad.net/~rvb/juju-core/cleanup-tempfile/+merge/158320
Point #24.
--
https://code.launchpad.net/~rvb/juju-core/cleanup-tempfile/+merge/158320
Your team MAAS Maintainers is requested to review the proposed merge of lp:~rvb/juju-core/cleanup-tempfile into lp:~maas-maintainers/juju-core/maas-provider-skeleton.
=== modified file 'environs/maas/environprovider_test.go'
--- environs/maas/environprovider_test.go 2013-04-11 09:34:08 +0000
+++ environs/maas/environprovider_test.go 2013-04-11 10:22:59 +0000
@@ -6,7 +6,6 @@
"launchpad.net/goyaml"
"launchpad.net/juju-core/environs/config"
"launchpad.net/juju-core/state"
- "os"
)
type EnvironProviderSuite struct {
@@ -36,10 +35,10 @@
c.Check(secretAttrs, DeepEquals, expectedAttrs)
}
-// create a temporary file with the given content. The caller is responsible
-// for cleaning up the file.
+// create a temporary file with the given content. The file will be cleaned
+// up at the end of the test calling this method.
func createTempFile(c *C, content []byte) string {
- file, err := ioutil.TempFile("", "")
+ file, err := ioutil.TempFile(c.MkDir(), "")
c.Assert(err, IsNil)
filename := file.Name()
err = ioutil.WriteFile(filename, content, 0644)
@@ -57,7 +56,6 @@
// Create a temporary file to act as the file where the instanceID
// is stored.
filename := createTempFile(c, yaml)
- defer os.Remove(filename)
// "Monkey patch" the value of _MAASInstanceFilename with the path
// to the temporary file.
old_MAASInstanceFilename := _MAASInstanceFilename
@@ -80,7 +78,6 @@
// Create a temporary file to act as the file where the instanceID
// is stored.
filename := createTempFile(c, yaml)
- defer os.Remove(filename)
// "Monkey patch" the value of _MAASInstanceFilename with the path
// to the temporary file.
old_MAASInstanceFilename := _MAASInstanceFilename
=== modified file 'environs/maas/util_test.go'
--- environs/maas/util_test.go 2013-04-11 09:34:08 +0000
+++ environs/maas/util_test.go 2013-04-11 10:22:59 +0000
@@ -11,7 +11,6 @@
"launchpad.net/juju-core/testing"
"launchpad.net/juju-core/trivial"
"launchpad.net/juju-core/version"
- "os"
)
type UtilSuite struct{}
@@ -117,7 +116,6 @@
hostname := "hostname"
yaml := fmt.Sprintf("instanceid: %s\nhostname: %s\n", instanceId, hostname)
filename := createTempFile(c, []byte(yaml))
- defer os.Remove(filename)
old_MAASInstanceFilename := _MAASInstanceFilename
_MAASInstanceFilename = filename
defer func() { _MAASInstanceFilename = old_MAASInstanceFilename }()