MCPcopy Create free account
hub / github.com/cli/cli / saveResponses

Method saveResponses

script/ghmock/store.go:187–205  ·  view source on GitHub ↗

saveResponses writes through a temporary file so a running server never reads a half-written file.

(responses responseSet)

Source from the content-addressed store, hash-verified

185// saveResponses writes through a temporary file so a running server never
186// reads a half-written file.
187func (s *state) saveResponses(responses responseSet) error {
188 data, err := json.MarshalIndent(responses, "", " ")
189 if err != nil {
190 return err
191 }
192 tmp, err := os.CreateTemp(s.dir, "responses-*.json")
193 if err != nil {
194 return err
195 }
196 defer os.Remove(tmp.Name())
197 if _, err := tmp.Write(append(data, '\n')); err != nil {
198 tmp.Close()
199 return err
200 }
201 if err := tmp.Close(); err != nil {
202 return err
203 }
204 return os.Rename(tmp.Name(), s.responsesPath())
205}
206
207func (s *state) appendLog(entries []loggedRequest) error {
208 return appendJSONL(s.logPath(), entries)

Callers 7

TestMockServerFunction · 0.95
TestCmdSetFunction · 0.95
TestCmdExportFunction · 0.95
TestCmdScaffoldFunction · 0.95
TestRunAllFunction · 0.95
cmdSetFunction · 0.80
cmdScaffoldFunction · 0.80

Calls 5

responsesPathMethod · 0.95
RemoveMethod · 0.65
NameMethod · 0.65
WriteMethod · 0.65
CloseMethod · 0.65

Tested by 5

TestMockServerFunction · 0.76
TestCmdSetFunction · 0.76
TestCmdExportFunction · 0.76
TestCmdScaffoldFunction · 0.76
TestRunAllFunction · 0.76