MCPcopy
hub / github.com/andeya/pholcus / TestFailure_Flush_FileOverwrite

Function TestFailure_Flush_FileOverwrite

app/aid/history/failure_test.go:124–152  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

122}
123
124func 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}

Callers

nothing calls this directly

Calls 4

flushMethod · 0.95
FileNameReplaceFunction · 0.92
newTestRequestFunction · 0.85
UniqueMethod · 0.80

Tested by

no test coverage detected