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

Method loadResponses

script/ghmock/store.go:160–183  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

158}
159
160func (s *state) loadResponses() (responseSet, error) {
161 data, err := os.ReadFile(s.responsesPath())
162 if errors.Is(err, fs.ErrNotExist) {
163 return responseSet{}, nil
164 }
165 if err != nil {
166 return nil, err
167 }
168 responses := responseSet{}
169 if len(bytes.TrimSpace(data)) == 0 {
170 return responses, nil
171 }
172 if err := json.Unmarshal(data, &responses); err != nil {
173 return nil, fmt.Errorf("reading %s: %w", s.responsesPath(), err)
174 }
175 for name, list := range responses {
176 for i, resp := range list {
177 if resp.RawBody != nil && len(resp.Body) > 0 {
178 return nil, fmt.Errorf("reading %s: %s response %d has both JSON and raw bodies", s.responsesPath(), name, i+1)
179 }
180 }
181 }
182 return responses, nil
183}
184
185// saveResponses writes through a temporary file so a running server never
186// reads a half-written file.

Callers 8

TestCmdSetAndResetFunction · 0.95
TestCmdSetFunction · 0.95
TestCmdExportFunction · 0.95
TestCmdScaffoldFunction · 0.95
ServeHTTPMethod · 0.80
cmdExportFunction · 0.80
cmdSetFunction · 0.80
cmdScaffoldFunction · 0.80

Calls 2

responsesPathMethod · 0.95
ErrorfMethod · 0.65

Tested by 4

TestCmdSetAndResetFunction · 0.76
TestCmdSetFunction · 0.76
TestCmdExportFunction · 0.76
TestCmdScaffoldFunction · 0.76