Added test for writing at start of file
@@ -43,3 +43,23 @@ func TestAppendToEndOfFile(t *testing.T) {
compareFileContents(t, fileName, "line 1\nline 2\nline 3\n")
}
}
+
+func TestWriteAtStartOfFile(t *testing.T){
+ for i := 0; i < 1; i++ {
+
+ fileName := tmpFile.Name()
+
+ f, err := os.OpenFile(fileName, os.O_WRONLY, 0600)
+ if err != nil {
+ t.Errorf("Open file for write at start: %v", err)
+ }
+
+ if _, err = f.WriteAt([]byte("line 4\n"),0); err != nil {
+ t.Errorf("WriteString-Start: %v", err)
+ }
+
+ f.Close()
+
+ compareFileContents(t, fileName, "line 4\nline 2\nline 3\n")
+ }
+}
\ No newline at end of file
