MCPcopy Create free account
hub / github.com/gavv/httpexpect / initPath

Method initPath

request.go:155–195  ·  view source on GitHub ↗
(opChain *chain, path string, pathargs ...interface{})

Source from the content-addressed store, hash-verified

153}
154
155func (r *Request) initPath(opChain *chain, path string, pathargs ...interface{}) {
156 if len(pathargs) != 0 {
157 var n int
158
159 var err error
160 path, err = interpol.WithFunc(path, func(k string, w io.Writer) error {
161 if n < len(pathargs) {
162 if pathargs[n] == nil {
163 opChain.fail(AssertionFailure{
164 Type: AssertValid,
165 Actual: &AssertionValue{pathargs},
166 Errors: []error{
167 fmt.Errorf("unexpected nil argument at index %d", n),
168 },
169 })
170 } else {
171 mustWrite(w, fmt.Sprint(pathargs[n]))
172 }
173 } else {
174 mustWrite(w, "{")
175 mustWrite(w, k)
176 mustWrite(w, "}")
177 }
178 n++
179 return nil
180 })
181
182 if err != nil {
183 opChain.fail(AssertionFailure{
184 Type: AssertValid,
185 Actual: &AssertionValue{path},
186 Errors: []error{
187 errors.New("invalid interpol string"),
188 err,
189 },
190 })
191 }
192 }
193
194 r.path = path
195}
196
197func (r *Request) initReq(opChain *chain, method string) {
198 httpReq, err := r.config.RequestFactory.NewRequest(method, r.config.BaseURL, nil)

Callers 1

newRequestFunction · 0.95

Calls 3

mustWriteFunction · 0.85
failMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected