summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/braintree/manners/test_helpers/temp_file.go
blob: c4aa263a07c1091f9b31ea83fc1d2d4f2971dcdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package test_helpers

import (
	"io/ioutil"
	"os"
)

type TempFile struct {
	*os.File
}

func NewTempFile(content []byte) (*TempFile, error) {
	f, err := ioutil.TempFile("", "graceful-test")
	if err != nil {
		return nil, err
	}

	f.Write(content)
	return &TempFile{f}, nil
}

func (tf *TempFile) Unlink() {
	if tf.File != nil {
		os.Remove(tf.Name())
		tf.File = nil
	}
}