Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions checks/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion client/lessons.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
OpEquals OperatorType = "eq"
OpGreaterThan OperatorType = "gt"
OpContains OperatorType = "contains"
OpNotContains OperatorType = "not_contains"
)

type HTTPTestJSONValue struct {
Expand All @@ -48,14 +49,15 @@ 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
}
Headers map[string]string
BodyJSON map[string]interface{}
Method string
Path string
Actions struct {
DelayRequestByMs *int32
}
Expand Down
25 changes: 19 additions & 6 deletions render/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type doneHttpMsg struct {
}

type startHttpMsg struct {
path string
url string
method string
}

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)}
}
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down