Skip to content

Commit

Permalink
feat: manditory labels and failures
Browse files Browse the repository at this point in the history
  • Loading branch information
taybart committed Apr 12, 2023
1 parent 1cb5b4b commit 8f6ecec
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
21 changes: 17 additions & 4 deletions example.rest
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
// vim: ft=hcl
locals {
url = "http://localhost:8080"
asdf = "world"
}

// test
request {
label = "hell_yeah"
request "get with header" {
method = "GET"
headers = [
"X-TEST: you:😄",
]
url = "${locals.url}/get"
}

request {
request "post with body" {
method = "POST"
url = "${locals.url}/post"
headers = [
Expand All @@ -28,3 +26,18 @@ request {
END
expect = 200
}

request "post with body that should fail" {
method = "POST"
url = "${locals.url}/post"
headers = [
"Content-Type: application/json",
]

body = <<END
{
"hello": "${locals.asdf}"
}
END
expect = 401
}
3 changes: 2 additions & 1 deletion request/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type Root struct {
} `hcl:"locals,block"`

Requests []*struct {
Body hcl.Body `hcl:",remain"`
Label string `hcl:"label,label"`
Body hcl.Body `hcl:",remain"`
} `hcl:"request,block"`
}
2 changes: 1 addition & 1 deletion request/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func parseFile(filename string) ([]Request, error) {
requests := []Request{}
labels := []string{}
for _, block := range root.Requests {
var req Request
req := Request{Label: block.Label}
if diags = gohcl.DecodeBody(block.Body, ctx, &req); diags.HasErrors() {
writeDiags(map[string]*hcl.File{filename: file}, diags)
return nil, fmt.Errorf("error decoding HCL configuration: %w", diags)
Expand Down
2 changes: 1 addition & 1 deletion request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Request struct {
Headers []string `hcl:"headers,optional"`
Query map[string]string `hcl:"query,optional"`
// extras
Label string `hcl:"label,optional"`
Label string `hcl:"label,label"`
Delay string `hcl:"delay,optional"`
Expect int `hcl:"expect,optional"`
}
Expand Down

0 comments on commit 8f6ecec

Please sign in to comment.