diff --git a/filet.go b/filet.go index b08765f..636fa4e 100644 --- a/filet.go +++ b/filet.go @@ -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 */ diff --git a/filet_test.go b/filet_test.go index 5c4facf..4e71504 100644 --- a/filet_test.go +++ b/filet_test.go @@ -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)