diff --git a/checks/http.go b/checks/http.go index c51480b..8815e20 100644 --- a/checks/http.go +++ b/checks/http.go @@ -47,6 +47,9 @@ func HttpTest( finalBaseURL = strings.TrimSuffix(finalBaseURL, "/") interpolatedPath := InterpolateVariables(request.Request.Path, variables) completeURL := fmt.Sprintf("%s%s", finalBaseURL, interpolatedPath) + if request.Request.FullURL != "" { + completeURL = InterpolateVariables(request.Request.FullURL, variables) + } var r *http.Request if request.Request.BodyJSON != nil { diff --git a/client/lessons.go b/client/lessons.go index 24dbe97..6de6501 100644 --- a/client/lessons.go +++ b/client/lessons.go @@ -25,6 +25,7 @@ const ( OpEquals OperatorType = "eq" OpGreaterThan OperatorType = "gt" OpContains OperatorType = "contains" + OpNotContains OperatorType = "not_contains" ) type HTTPTestJSONValue struct { @@ -48,6 +49,8 @@ type LessonDataHTTPTests struct { ResponseVariables []ResponseVariable Tests []HTTPTest Request struct { + FullURL string // overrides BaseURL and Path if set + Path string BasicAuth *struct { Username string Password string @@ -55,7 +58,6 @@ type LessonDataHTTPTests struct { Headers map[string]string BodyJSON map[string]interface{} Method string - Path string Actions struct { DelayRequestByMs *int32 } diff --git a/render/http.go b/render/http.go index 094106b..0b6215e 100644 --- a/render/http.go +++ b/render/http.go @@ -23,7 +23,7 @@ type doneHttpMsg struct { } type startHttpMsg struct { - path string + url string method string } @@ -78,7 +78,7 @@ func (m httpRootModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, tea.Quit case startHttpMsg: - m.reqs = append(m.reqs, httpReqModel{request: fmt.Sprintf("%s %s", msg.method, msg.path), tests: []testModel{}}) + m.reqs = append(m.reqs, httpReqModel{request: fmt.Sprintf("%s %s", msg.method, msg.url), tests: []testModel{}}) return m, nil case resolveHttpMsg: @@ -210,7 +210,14 @@ func httpRenderer( defer wg.Done() for i, req := range data.HttpTests.Requests { - ch <- startHttpMsg{path: req.Request.Path, method: req.Request.Method} + url := req.Request.Path + if req.Request.FullURL != "" { + url = req.Request.FullURL + } + ch <- startHttpMsg{ + url: checks.InterpolateVariables(url, results[i].Variables), + method: req.Request.Method, + } for _, test := range req.Tests { ch <- startTestMsg{text: prettyPrintHTTPTest(test, results[i].Variables)} } @@ -250,13 +257,17 @@ func prettyPrintHTTPTest(test api.HTTPTest, variables map[string]string) string return fmt.Sprintf("Expecting status code: %d", *test.StatusCode) } if test.BodyContains != nil { - return fmt.Sprintf("Expecting JSON body to contain: %s", *test.BodyContains) + interpolated := checks.InterpolateVariables(*test.BodyContains, variables) + return fmt.Sprintf("Expecting JSON body to contain: %s", interpolated) } if test.BodyContainsNone != nil { - return fmt.Sprintf("Expecting JSON body to not contain: %s", *test.BodyContainsNone) + interpolated := checks.InterpolateVariables(*test.BodyContainsNone, variables) + return fmt.Sprintf("Expecting JSON body to not contain: %s", interpolated) } if test.HeadersContain != nil { - return fmt.Sprintf("Expecting header to contain: '%s: %v'", test.HeadersContain.Key, test.HeadersContain.Value) + interpolatedKey := checks.InterpolateVariables(test.HeadersContain.Key, variables) + interpolatedValue := checks.InterpolateVariables(test.HeadersContain.Value, variables) + return fmt.Sprintf("Expecting header to contain: '%s: %v'", interpolatedKey, interpolatedValue) } if test.JSONValue != nil { var val any @@ -274,6 +285,8 @@ func prettyPrintHTTPTest(test api.HTTPTest, variables map[string]string) string op = "to be greater than" } else if test.JSONValue.Operator == api.OpContains { op = "contains" + } else if test.JSONValue.Operator == api.OpNotContains { + op = "to not contain" } expecting := fmt.Sprintf("Expecting JSON at %v %s %v", test.JSONValue.Path, op, val) return checks.InterpolateVariables(expecting, variables)