Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions filet.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ func TmpFile(t TestReporter, dir string, content string) afero.File {
return file
}

/*
TmpBinFile Creates a tmp file we can write byte slice to for us to use when testing
*/
func TmpBinFile(t TestReporter, dir string, content []byte) afero.File {
file, err := afero.TempFile(appFs, dir, "file")
defer file.Close()

if err != nil {
t.Error("Failed to create the tmpFile: "+file.Name(), err)
}

file.Write(content)
Files = append(Files, file.Name())

return file
}

/*
File Creates a specified file for us to use when testing
*/
Expand Down
16 changes: 16 additions & 0 deletions filet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ func TestTmpFile(t *testing.T) {
"TmpFile should create a file with content")
}

func TestTmpBinFile(t *testing.T) {
defer CleanUp(t)

// Test that file is actually created
file := TmpBinFile(t, "", []byte(""))
assert.Equal(t, Exists(t, file.Name()), true,
"TmpFile should create the file")

// Test that the content exists in the file
file = TmpBinFile(t, "", []byte("hey there"))
result := FileSays(t, file.Name(), []byte("hey there"))
assert.Equal(t, result, true,
"TmpFile should create a file with content")
}


func TestFile(t *testing.T) {
defer CleanUp(t)

Expand Down