Skip to content

Commit 161708c

Browse files
authored
add support for not_contains operator and fullurl option (#64)
1 parent 3884101 commit 161708c

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

checks/http.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ func HttpTest(
4747
finalBaseURL = strings.TrimSuffix(finalBaseURL, "/")
4848
interpolatedPath := InterpolateVariables(request.Request.Path, variables)
4949
completeURL := fmt.Sprintf("%s%s", finalBaseURL, interpolatedPath)
50+
if request.Request.FullURL != "" {
51+
completeURL = InterpolateVariables(request.Request.FullURL, variables)
52+
}
5053

5154
var r *http.Request
5255
if request.Request.BodyJSON != nil {

client/lessons.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const (
2525
OpEquals OperatorType = "eq"
2626
OpGreaterThan OperatorType = "gt"
2727
OpContains OperatorType = "contains"
28+
OpNotContains OperatorType = "not_contains"
2829
)
2930

3031
type HTTPTestJSONValue struct {
@@ -48,14 +49,15 @@ type LessonDataHTTPTests struct {
4849
ResponseVariables []ResponseVariable
4950
Tests []HTTPTest
5051
Request struct {
52+
FullURL string // overrides BaseURL and Path if set
53+
Path string
5154
BasicAuth *struct {
5255
Username string
5356
Password string
5457
}
5558
Headers map[string]string
5659
BodyJSON map[string]interface{}
5760
Method string
58-
Path string
5961
Actions struct {
6062
DelayRequestByMs *int32
6163
}

render/http.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type doneHttpMsg struct {
2323
}
2424

2525
type startHttpMsg struct {
26-
path string
26+
url string
2727
method string
2828
}
2929

@@ -78,7 +78,7 @@ func (m httpRootModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
7878
return m, tea.Quit
7979

8080
case startHttpMsg:
81-
m.reqs = append(m.reqs, httpReqModel{request: fmt.Sprintf("%s %s", msg.method, msg.path), tests: []testModel{}})
81+
m.reqs = append(m.reqs, httpReqModel{request: fmt.Sprintf("%s %s", msg.method, msg.url), tests: []testModel{}})
8282
return m, nil
8383

8484
case resolveHttpMsg:
@@ -210,7 +210,14 @@ func httpRenderer(
210210
defer wg.Done()
211211

212212
for i, req := range data.HttpTests.Requests {
213-
ch <- startHttpMsg{path: req.Request.Path, method: req.Request.Method}
213+
url := req.Request.Path
214+
if req.Request.FullURL != "" {
215+
url = req.Request.FullURL
216+
}
217+
ch <- startHttpMsg{
218+
url: checks.InterpolateVariables(url, results[i].Variables),
219+
method: req.Request.Method,
220+
}
214221
for _, test := range req.Tests {
215222
ch <- startTestMsg{text: prettyPrintHTTPTest(test, results[i].Variables)}
216223
}
@@ -250,13 +257,17 @@ func prettyPrintHTTPTest(test api.HTTPTest, variables map[string]string) string
250257
return fmt.Sprintf("Expecting status code: %d", *test.StatusCode)
251258
}
252259
if test.BodyContains != nil {
253-
return fmt.Sprintf("Expecting JSON body to contain: %s", *test.BodyContains)
260+
interpolated := checks.InterpolateVariables(*test.BodyContains, variables)
261+
return fmt.Sprintf("Expecting JSON body to contain: %s", interpolated)
254262
}
255263
if test.BodyContainsNone != nil {
256-
return fmt.Sprintf("Expecting JSON body to not contain: %s", *test.BodyContainsNone)
264+
interpolated := checks.InterpolateVariables(*test.BodyContainsNone, variables)
265+
return fmt.Sprintf("Expecting JSON body to not contain: %s", interpolated)
257266
}
258267
if test.HeadersContain != nil {
259-
return fmt.Sprintf("Expecting header to contain: '%s: %v'", test.HeadersContain.Key, test.HeadersContain.Value)
268+
interpolatedKey := checks.InterpolateVariables(test.HeadersContain.Key, variables)
269+
interpolatedValue := checks.InterpolateVariables(test.HeadersContain.Value, variables)
270+
return fmt.Sprintf("Expecting header to contain: '%s: %v'", interpolatedKey, interpolatedValue)
260271
}
261272
if test.JSONValue != nil {
262273
var val any
@@ -274,6 +285,8 @@ func prettyPrintHTTPTest(test api.HTTPTest, variables map[string]string) string
274285
op = "to be greater than"
275286
} else if test.JSONValue.Operator == api.OpContains {
276287
op = "contains"
288+
} else if test.JSONValue.Operator == api.OpNotContains {
289+
op = "to not contain"
277290
}
278291
expecting := fmt.Sprintf("Expecting JSON at %v %s %v", test.JSONValue.Path, op, val)
279292
return checks.InterpolateVariables(expecting, variables)

0 commit comments

Comments
 (0)