-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
48 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,26 @@ | ||
package fftest | ||
|
||
import ( | ||
"io/ioutil" | ||
"math/rand" | ||
"os" | ||
"path/filepath" | ||
"strconv" | ||
"testing" | ||
) | ||
|
||
// TempFile uses ioutil.TempFile to create a temporary file with the given | ||
// content. Use the cleanup func to remove the file. | ||
func TempFile(t *testing.T, content string) (filename string, cleanup func()) { | ||
// TempFile returns the filename of a temporary file that has been created with | ||
// the provided content. The file is created in t.TempDir(), which is | ||
// automatically removed when the test finishes. | ||
func TempFile(t *testing.T, content string) string { | ||
t.Helper() | ||
|
||
f, err := ioutil.TempFile("", "fftest_") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if _, err := f.Write([]byte(content)); err != nil { | ||
t.Fatal(err) | ||
} | ||
filename := filepath.Join(t.TempDir(), strconv.Itoa(rand.Int())) | ||
|
||
if err := f.Close(); err != nil { | ||
if err := os.WriteFile(filename, []byte(content), 0600); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
cleanup = func() { | ||
if err := os.Remove(f.Name()); err != nil { | ||
t.Errorf("os.Remove(%q): %v", f.Name(), err) | ||
} | ||
} | ||
t.Logf("created %s", filename) | ||
|
||
return f.Name(), cleanup | ||
return filename | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/peterbourgon/ff/v3 | ||
|
||
go 1.16 | ||
go 1.18 | ||
|
||
require ( | ||
github.com/pelletier/go-toml v1.9.5 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters