(t *testing.T)
| 122 | } |
| 123 | |
| 124 | func TestFailure_Flush_FileOverwrite(t *testing.T) { |
| 125 | tmp := t.TempDir() |
| 126 | dir := filepath.Join(tmp, config.WorkRoot, config.HistoryTag) |
| 127 | if err := os.MkdirAll(dir, 0777); err != nil { |
| 128 | t.Fatalf("MkdirAll: %v", err) |
| 129 | } |
| 130 | orig, _ := os.Getwd() |
| 131 | os.Chdir(tmp) |
| 132 | defer os.Chdir(orig) |
| 133 | |
| 134 | fileName := filepath.Join(dir, "history__n__overwrite") |
| 135 | if err := os.WriteFile(fileName, []byte("old"), 0644); err != nil { |
| 136 | t.Fatalf("WriteFile: %v", err) |
| 137 | } |
| 138 | req := newTestRequest("http://c.com") |
| 139 | f := &Failure{ |
| 140 | tabName: util.FileNameReplace("history__n__overwrite"), |
| 141 | fileName: fileName, |
| 142 | list: map[string]*request.Request{req.Unique(): req}, |
| 143 | } |
| 144 | r := f.flush("file") |
| 145 | if r.IsErr() { |
| 146 | t.Fatalf("flush: %v", r.UnwrapErr()) |
| 147 | } |
| 148 | data, _ := os.ReadFile(fileName) |
| 149 | if len(data) < 10 { |
| 150 | t.Errorf("flush should overwrite file, got %d bytes", len(data)) |
| 151 | } |
| 152 | } |
nothing calls this directly
no test coverage detected