diff --git a/cmd/run.go b/cmd/run.go index 32d501f5c..3a2edf262 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -402,7 +402,8 @@ func (o *runOption) runSuite(loader testing.Loader, dataContext map[string]inter default: o.limiter.Accept() - ctxWithTimeout, _ := context.WithTimeout(ctx, o.requestTimeout) + ctxWithTimeout, cancel := context.WithTimeout(ctx, o.requestTimeout) + defer cancel() // Ensure context is always cancelled when leaving this scope ctxWithTimeout = context.WithValue(ctxWithTimeout, runner.ContextKey("").ParentDir(), loader.GetContext()) output, err = suiteRunner.RunTestCase(&testCase, dataContext, ctxWithTimeout) diff --git a/pkg/mock/types.go b/pkg/mock/types.go index 06b490bb9..b37911757 100644 --- a/pkg/mock/types.go +++ b/pkg/mock/types.go @@ -16,65 +16,65 @@ limitations under the License. package mock type Object struct { - Name string `yaml:"name" json:"name"` - InitCount *int `yaml:"initCount" json:"initCount"` - Sample string `yaml:"sample" json:"sample"` + Name string `yaml:"name" json:"name"` + InitCount *int `yaml:"initCount" json:"initCount"` + Sample string `yaml:"sample" json:"sample"` } type Item struct { - Name string `yaml:"name" json:"name"` - Request Request `yaml:"request" json:"request"` - Response Response `yaml:"response" json:"response"` - Param map[string]interface{} + Name string `yaml:"name" json:"name"` + Request Request `yaml:"request" json:"request"` + Response Response `yaml:"response" json:"response"` + Param map[string]interface{} } type Request struct { - Protocol string `yaml:"protocol" json:"protocol"` - Path string `yaml:"path" json:"path"` - Method string `yaml:"method" json:"method"` - Header map[string]string `yaml:"header" json:"header"` - Body string `yaml:"body" json:"body"` + Protocol string `yaml:"protocol" json:"protocol"` + Path string `yaml:"path" json:"path"` + Method string `yaml:"method" json:"method"` + Header map[string]string `yaml:"header" json:"header"` + Body string `yaml:"body" json:"body"` } type RequestWithAuth struct { - Request `yaml:",inline"` - BearerAPI string `yaml:"bearerAPI" json:"bearerAPI"` - Username string `yaml:"username" json:"username"` - Password string `yaml:"password" json:"password"` + Request `yaml:",inline"` + BearerAPI string `yaml:"bearerAPI" json:"bearerAPI"` + Username string `yaml:"username" json:"username"` + Password string `yaml:"password" json:"password"` } type Response struct { - Encoder string `yaml:"encoder" json:"encoder"` - Body string `yaml:"body" json:"body"` - BodyFromFile string `yaml:"bodyFromFile" json:"bodyFromFile"` - Header map[string]string `yaml:"header" json:"header"` - StatusCode int `yaml:"statusCode" json:"statusCode"` - BodyData []byte + Encoder string `yaml:"encoder" json:"encoder"` + Body string `yaml:"body" json:"body"` + BodyFromFile string `yaml:"bodyFromFile" json:"bodyFromFile"` + Header map[string]string `yaml:"header" json:"header"` + StatusCode int `yaml:"statusCode" json:"statusCode"` + BodyData []byte } type Webhook struct { - Name string `yaml:"name" json:"name"` - Timer string `yaml:"timer" json:"timer"` - Param map[string]string `yaml:"param" json:"param"` - Request RequestWithAuth `yaml:"request" json:"request"` + Name string `yaml:"name" json:"name"` + Timer string `yaml:"timer" json:"timer"` + Param map[string]string `yaml:"param" json:"param"` + Request RequestWithAuth `yaml:"request" json:"request"` } type Proxy struct { - Prefix string `yaml:"prefix" json:"prefix"` - Port int `yaml:"port" json:"port"` - Path string `yaml:"path" json:"path"` - Target string `yaml:"target" json:"target"` - RequestAmend RequestAmend `yaml:"requestAmend" json:"requestAmend"` - Protocol string `yaml:"protocol" json:"protocol"` + Prefix string `yaml:"prefix" json:"prefix"` + Port int `yaml:"port" json:"port"` + Path string `yaml:"path" json:"path"` + Target string `yaml:"target" json:"target"` + RequestAmend RequestAmend `yaml:"requestAmend" json:"requestAmend"` + Protocol string `yaml:"protocol" json:"protocol"` } type RequestAmend struct { - BodyPatch string `yaml:"bodyPatch" json:"bodyPatch"` + BodyPatch string `yaml:"bodyPatch" json:"bodyPatch"` } type Server struct { - Objects []Object `yaml:"objects" json:"objects"` - Items []Item `yaml:"items" json:"items"` - Proxies []Proxy `yaml:"proxies" json:"proxies"` - Webhooks []Webhook `yaml:"webhooks" json:"webhooks"` + Objects []Object `yaml:"objects" json:"objects"` + Items []Item `yaml:"items" json:"items"` + Proxies []Proxy `yaml:"proxies" json:"proxies"` + Webhooks []Webhook `yaml:"webhooks" json:"webhooks"` }