Skip to content

Commit

Permalink
Revert "merge tmpFile and tempFile usages"
Browse files Browse the repository at this point in the history
This reverts commit 7607f9c.

The old test tempFile function is not general purpose and sets up a
static file within a directory created by the tempDir helper. This
functionality needs to be preserved, so the correct plan of action would
be to preserve this functionality while moving the function name to
another, logical name such as tempTestFile.
  • Loading branch information
vancluever committed Jan 8, 2019
1 parent 7607f9c commit 1ebd7bf
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (c *Client) checksumFromFile(checksumFile string, src *url.URL) (*fileCheck
return nil, err
}

tempfile, err := tempFile("", filepath.Base(checksumFileURL.Path))
tempfile, err := tmpFile("", filepath.Base(checksumFileURL.Path))
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions client_option_progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ func TestGet_progress(t *testing.T) {
defer s.Close()

{ // dl without tracking
dst := mustString(tempFile("", ""))
dst := tempFile(t)
if err := GetFile(dst, s.URL+"/file?thig=this&that"); err != nil {
t.Fatalf("download failed: %v", err)
}
}

{ // tracking
p := &MockProgressTracking{}
dst := mustString(tempFile("", ""))
dst := tempFile(t)
if err := GetFile(dst, s.URL+"/file?thig=this&that", WithProgress(p)); err != nil {
t.Fatalf("download failed: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"io/ioutil"
)

func tempFile(dir, pattern string) (string, error) {
func tmpFile(dir, pattern string) (string, error) {
f, err := ioutil.TempFile(dir, pattern)
if err != nil {
return "", err
Expand Down
4 changes: 2 additions & 2 deletions get_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestFileGetter_dirSymlink(t *testing.T) {

func TestFileGetter_GetFile(t *testing.T) {
g := new(FileGetter)
dst := mustString(tempFile("", ""))
dst := tempFile(t)
defer os.Remove(dst)

// With a dir that doesn't exist
Expand All @@ -130,7 +130,7 @@ func TestFileGetter_GetFile_Copy(t *testing.T) {
g := new(FileGetter)
g.Copy = true

dst := mustString(tempFile("", ""))
dst := tempFile(t)
defer os.Remove(dst)

// With a dir that doesn't exist
Expand Down
2 changes: 1 addition & 1 deletion get_git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func TestGitGetter_GetFile(t *testing.T) {
}

g := new(GitGetter)
dst := mustString(tempFile("", ""))
dst := tempFile(t)
defer os.Remove(dst)

repo := testGitRepo(t, "file")
Expand Down
2 changes: 1 addition & 1 deletion get_hg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestHgGetter_GetFile(t *testing.T) {
}

g := new(HgGetter)
dst := mustString(tempFile("", ""))
dst := tempFile(t)
defer os.Remove(dst)

// Download
Expand Down
2 changes: 1 addition & 1 deletion get_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func TestHttpGetter_file(t *testing.T) {
defer ln.Close()

g := new(HttpGetter)
dst := mustString(tempFile("", ""))
dst := tempFile(t)
defer os.RemoveAll(dst)

var u url.URL
Expand Down
6 changes: 3 additions & 3 deletions get_s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestS3Getter_subdir(t *testing.T) {

func TestS3Getter_GetFile(t *testing.T) {
g := new(S3Getter)
dst := mustString(tempFile("", ""))
dst := tempFile(t)
defer os.Remove(dst)

// Download
Expand All @@ -82,7 +82,7 @@ func TestS3Getter_GetFile(t *testing.T) {

func TestS3Getter_GetFile_badParams(t *testing.T) {
g := new(S3Getter)
dst := mustString(tempFile("", ""))
dst := tempFile(t)
defer os.Remove(dst)

// Download
Expand All @@ -100,7 +100,7 @@ func TestS3Getter_GetFile_badParams(t *testing.T) {

func TestS3Getter_GetFile_notfound(t *testing.T) {
g := new(S3Getter)
dst := mustString(tempFile("", ""))
dst := tempFile(t)
defer os.Remove(dst)

// Download
Expand Down
16 changes: 8 additions & 8 deletions get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func TestGetAny_dir(t *testing.T) {
}

func TestGetFile(t *testing.T) {
dst := mustString(tempFile("", ""))
dst := tempFile(t)
defer os.Remove(dst)
u := testModule("basic-file/foo.txt")

Expand All @@ -237,7 +237,7 @@ func TestGetFile(t *testing.T) {
}

func TestGetFile_archive(t *testing.T) {
dst := mustString(tempFile("", ""))
dst := tempFile(t)
defer os.Remove(dst)
u := testModule("basic-file-archive/archive.tar.gz")

Expand All @@ -250,7 +250,7 @@ func TestGetFile_archive(t *testing.T) {
}

func TestGetFile_archiveChecksum(t *testing.T) {
dst := mustString(tempFile("", ""))
dst := tempFile(t)
defer os.Remove(dst)
u := testModule(
"basic-file-archive/archive.tar.gz?checksum=md5:fbd90037dacc4b1ab40811d610dde2f0")
Expand All @@ -264,7 +264,7 @@ func TestGetFile_archiveChecksum(t *testing.T) {
}

func TestGetFile_archiveNoUnarchive(t *testing.T) {
dst := mustString(tempFile("", ""))
dst := tempFile(t)
defer os.Remove(dst)
u := testModule("basic-file-archive/archive.tar.gz")
u += "?archive=false"
Expand Down Expand Up @@ -352,7 +352,7 @@ func TestGetFile_checksum(t *testing.T) {
u := testModule("basic-file/foo.txt") + tc.Append

func() {
dst := mustString(tempFile("", ""))
dst := tempFile(t)
defer os.Remove(dst)
if err := GetFile(dst, u); (err != nil) != tc.Err {
t.Fatalf("append: %s\n\nerr: %s", tc.Append, err)
Expand Down Expand Up @@ -432,7 +432,7 @@ func TestGetFile_checksum_from_file(t *testing.T) {
for _, tc := range cases {
u := checksums + "/content.txt" + tc.Append
t.Run(tc.Append, func(t *testing.T) {
dst := mustString(tempFile("", ""))
dst := tempFile(t)
defer os.Remove(dst)
if err := GetFile(dst, u); (err != nil) != tc.WantErr {
t.Fatalf("append: %s\n\nerr: %s", tc.Append, err)
Expand All @@ -447,7 +447,7 @@ func TestGetFile_checksum_from_file(t *testing.T) {
}

func TestGetFile_checksumURL(t *testing.T) {
dst := mustString(tempFile("", ""))
dst := tempFile(t)
defer os.Remove(dst)
u := testModule("basic-file/foo.txt") + "?checksum=md5:09f7e02f1290be211da707a266f153b3"

Expand Down Expand Up @@ -487,7 +487,7 @@ func TestGetFile_filename(t *testing.T) {
}

func TestGetFile_checksumSkip(t *testing.T) {
dst := mustString(tempFile("", ""))
dst := tempFile(t)
defer os.Remove(dst)
u := testModule("basic-file/foo.txt") + "?checksum=md5:09f7e02f1290be211da707a266f153b3"

Expand Down
8 changes: 3 additions & 5 deletions module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ func tempDir(t *testing.T) string {
return dir
}

func mustString(s string, err error) string {
if err != nil {
panic("err: " + err.Error())
}
return s
func tempFile(t *testing.T) string {
dir := tempDir(t)
return filepath.Join(dir, "foo")
}

func testModule(n string) string {
Expand Down

0 comments on commit 1ebd7bf

Please sign in to comment.