Skip to content

Commit cb1d1d8

Browse files
authored
Merge pull request #12 from taybart/feature/runtime-vars
Runtime variables
2 parents c9f25a1 + 6cce87f commit cb1d1d8

12 files changed

+378
-153
lines changed

builder.go

+23-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,34 @@ import (
1010
"os"
1111
"path/filepath"
1212
"strings"
13+
"time"
14+
15+
"github.com/taybart/log"
1316
)
1417

18+
type request struct {
19+
label string
20+
skip bool
21+
r *http.Request
22+
delay time.Duration
23+
expectation expectation
24+
outputs map[string]string
25+
}
26+
1527
// type builder struct{}
1628

1729
// buildRequest : generate http.Request from parsed input
18-
func buildRequest(input metaRequest) (req request, err error) {
30+
func buildRequest(input metaRequest, variables map[string]restVar) (req request, err error) {
31+
if input.reinterpret {
32+
log.Debug("Re-interpreting request", variables)
33+
l := newLexer(false)
34+
l.variables = variables
35+
input, err = l.parseBlock(input.block)
36+
if err != nil {
37+
return
38+
}
39+
}
40+
1941
if err = isValidMetaRequest(input); err != nil {
2042
return
2143
}

cmd/rest/main.go

+7
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,18 @@ func help() {
5555

5656
func main() {
5757
flag.Parse()
58+
5859
log.SetPlain()
5960
log.SetLevel(log.WARN)
6061
if verbose {
6162
log.SetLevel(log.DEBUG)
6263
}
64+
6365
if servelog || servedir {
6466
serve(servedir, local, port)
6567
return
6668
}
69+
6770
r := rest.New()
6871
if nocolor {
6972
r.NoColor()
@@ -107,6 +110,7 @@ func main() {
107110

108111
func readFiles(r *rest.Rest) {
109112
for _, f := range fns {
113+
log.Debug("Reading file %s...", f)
110114
if fileExists(f) {
111115
valid, err := r.IsRestFile(f)
112116
if !valid {
@@ -116,12 +120,15 @@ func readFiles(r *rest.Rest) {
116120
err = r.Read(f)
117121
if err != nil {
118122
log.Error("Read error", err)
123+
continue
119124
}
125+
log.Debug("done\n")
120126
}
121127
}
122128
}
123129

124130
func exec(r *rest.Rest) {
131+
log.Debug("\nExecuting all requests\n")
125132
if index >= 0 {
126133
res, err := r.ExecIndex(index)
127134
if err != nil {

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module github.com/taybart/rest
22

3-
go 1.13
3+
go 1.15
44

55
require (
66
github.com/matryer/is v1.2.0
7-
github.com/taybart/log v1.1.1
7+
github.com/taybart/log v1.2.2
88
)

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A=
22
github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
3-
github.com/taybart/log v1.1.1 h1:cuYtzjywA8D1rxmmyQ7ry5fwduAcktmxr7/WZxAf1Xw=
4-
github.com/taybart/log v1.1.1/go.mod h1:bLpgJt6GrTPJNabumQPcFTaYJnGwj7mSMs/OQwTDAdE=
3+
github.com/taybart/log v1.2.2 h1:jlg3dibUsaanJLzofXzRmBMD+JHHPqbXiYpXdgXTYa8=
4+
github.com/taybart/log v1.2.2/go.mod h1:e9MmKdjMsNxSFbn46ag778NSmhFrx9yLC60CDRRcSOo=

0 commit comments

Comments
 (0)