func TestCreateTempFileWithContent(t *testing.T) { Convey("Given a contents string and file permissions", t, func() { contents := "This is a text about nothing.\n" perms := os.FileMode(0600) Convey("It should create a temporary file with the given contents", func() { tmpFile, err := file.Temp(contents, perms) So(err, ShouldBeNil) tmpFile.Close() tmpFilename := tmpFile.Name() defer os.Remove(tmpFilename) byteContent, err := ioutil.ReadFile(tmpFilename) So(contents, ShouldEqual, string(byteContent)) fi, err := os.Lstat(tmpFilename) So(err, ShouldBeNil) So(fi.Mode(), ShouldEqual, perms) }) }) }
func (tf *TempFile) Enter() error { if tf.Permissions == 0 { tf.Permissions = os.FileMode(0600) } src, err := file.Temp(tf.Content, tf.Permissions) tf.source = src tf.fname = src.Name() return err }