(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func TestWriteReadFile(t *testing.T) { |
| 11 | |
| 12 | dir := t.TempDir() |
| 13 | |
| 14 | wdBackup, err := os.Getwd() |
| 15 | if err != nil { |
| 16 | t.Fatalf("Error getting current working directory: %v", err) |
| 17 | } |
| 18 | err = os.Chdir(dir) |
| 19 | if err != nil { |
| 20 | t.Fatalf("Error changing working directory: %v", err) |
| 21 | } |
| 22 | |
| 23 | // 8. Delete temp folder |
| 24 | defer func() { |
| 25 | err = os.Chdir(wdBackup) |
| 26 | if err != nil { |
| 27 | t.Fatalf("Error changing dir back: %v", err) |
| 28 | } |
| 29 | }() |
| 30 | |
| 31 | err = WriteToFile([]byte("Some Content"), "someDir/someFile") |
| 32 | if err != nil { |
| 33 | t.Fatalf("Error using WriteToFile: %v", err) |
| 34 | } |
| 35 | |
| 36 | content, err := ReadFile("someDir/someFile", -1) |
| 37 | if err != nil { |
| 38 | t.Fatalf("Error using ReadFile without limit: %v", err) |
| 39 | } |
| 40 | assert.Equal(t, "Some Content", string(content), "File contains wrong content") |
| 41 | |
| 42 | content, err = ReadFile("someDir/someFile", 4) |
| 43 | if err != nil { |
| 44 | t.Fatalf("Error using ReadFile with limit: %v", err) |
| 45 | } |
| 46 | assert.Equal(t, "Some", string(content), "File contains wrong content or wrong content returned") |
| 47 | |
| 48 | _, err = ReadFile("", 1) |
| 49 | assert.Equal(t, true, err != nil, "No error when reading file without filename") |
| 50 | _, err = ReadFile("someDir", 1) |
| 51 | assert.Equal(t, true, err != nil, "No error when reading dir like a file") |
| 52 | } |
| 53 | |
| 54 | func TestCopy(t *testing.T) { |
| 55 |
nothing calls this directly
no test coverage detected