Skip to content

Commit 8f6ecec

Browse files
committed
feat: manditory labels and failures
1 parent 1cb5b4b commit 8f6ecec

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

example.rest

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
// vim: ft=hcl
21
locals {
32
url = "http://localhost:8080"
43
asdf = "world"
54
}
65

76
// test
8-
request {
9-
label = "hell_yeah"
7+
request "get with header" {
108
method = "GET"
119
headers = [
1210
"X-TEST: you:😄",
1311
]
1412
url = "${locals.url}/get"
1513
}
1614

17-
request {
15+
request "post with body" {
1816
method = "POST"
1917
url = "${locals.url}/post"
2018
headers = [
@@ -28,3 +26,18 @@ request {
2826
END
2927
expect = 200
3028
}
29+
30+
request "post with body that should fail" {
31+
method = "POST"
32+
url = "${locals.url}/post"
33+
headers = [
34+
"Content-Type: application/json",
35+
]
36+
37+
body = <<END
38+
{
39+
"hello": "${locals.asdf}"
40+
}
41+
END
42+
expect = 401
43+
}

request/config.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type Root struct {
88
} `hcl:"locals,block"`
99

1010
Requests []*struct {
11-
Body hcl.Body `hcl:",remain"`
11+
Label string `hcl:"label,label"`
12+
Body hcl.Body `hcl:",remain"`
1213
} `hcl:"request,block"`
1314
}

request/file.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func parseFile(filename string) ([]Request, error) {
3434
requests := []Request{}
3535
labels := []string{}
3636
for _, block := range root.Requests {
37-
var req Request
37+
req := Request{Label: block.Label}
3838
if diags = gohcl.DecodeBody(block.Body, ctx, &req); diags.HasErrors() {
3939
writeDiags(map[string]*hcl.File{filename: file}, diags)
4040
return nil, fmt.Errorf("error decoding HCL configuration: %w", diags)

request/request.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type Request struct {
2020
Headers []string `hcl:"headers,optional"`
2121
Query map[string]string `hcl:"query,optional"`
2222
// extras
23-
Label string `hcl:"label,optional"`
23+
Label string `hcl:"label,label"`
2424
Delay string `hcl:"delay,optional"`
2525
Expect int `hcl:"expect,optional"`
2626
}

0 commit comments

Comments
 (0)