Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix string escapes of capture.Runbook #149

Merged
merged 1 commit into from
Sep 16, 2022
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
4 changes: 2 additions & 2 deletions capture/runbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (c *cRunbook) CaptureHTTPResponse(name string, res *http.Response) {
continue
}
for i, v := range res.Header[k] {
cond = append(cond, fmt.Sprintf("current.res.headers['%s'][%d] == '%s'", k, i, v))
cond = append(cond, fmt.Sprintf("current.res.headers['%s'][%d] == %#v", k, i, v))
}
}

Expand Down Expand Up @@ -507,7 +507,7 @@ func (c *cRunbook) captureGRPCResponseMetadata(key string, m map[string][]string
})
for _, k := range keys {
for i, v := range m[k] {
cond := fmt.Sprintf("current.res.%s['%s'][%d] == '%s'", key, k, i, v)
cond := fmt.Sprintf("current.res.%s['%s'][%d] == %#v", key, k, i, v)
r.currentGRPCTestCond = append(r.currentGRPCTestCond, cond)
}
}
Expand Down
22 changes: 11 additions & 11 deletions testdata/grpc.yml.runbook.golden
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ steps:
num: 3
request_time: "2022-06-25T05:24:43.861872Z"
test: |
current.res.headers['content-type'][0] == 'application/grpc'
&& current.res.headers['hello'][0] == 'header'
&& current.res.trailers['hello'][0] == 'trailer'
current.res.headers['content-type'][0] == "application/grpc"
&& current.res.headers['hello'][0] == "header"
&& current.res.trailers['hello'][0] == "trailer"
&& compare(current.res.message, {"create_time":"2022-06-25T05:24:43.861872Z","message":"hello","num":32})
&& current.res.status == 0
- greq:
Expand All @@ -28,9 +28,9 @@ steps:
test: |
compare(current.res.messages[0], {"create_time":"2022-06-25T05:24:43.861872Z","message":"hello","num":33})
&& compare(current.res.messages[1], {"create_time":"2022-06-25T05:24:44.382783Z","message":"hello","num":34})
&& current.res.headers['content-type'][0] == 'application/grpc'
&& current.res.headers['listhello'][0] == 'header'
&& current.res.trailers['listhello'][0] == 'trailer'
&& current.res.headers['content-type'][0] == "application/grpc"
&& current.res.headers['listhello'][0] == "header"
&& current.res.trailers['listhello'][0] == "trailer"
&& current.res.status == 0
- greq:
grpctest.GrpcTestService/MultiHello:
Expand All @@ -45,9 +45,9 @@ steps:
request_time: "2022-06-25T05:24:43.861872Z"
test: |
compare(current.res.message, {"create_time":"2022-06-25T05:24:45.382783Z","message":"hello","num":35})
&& current.res.headers['content-type'][0] == 'application/grpc'
&& current.res.headers['multihello'][0] == 'header'
&& current.res.trailers['multihello'][0] == 'trailer'
&& current.res.headers['content-type'][0] == "application/grpc"
&& current.res.headers['multihello'][0] == "header"
&& current.res.trailers['multihello'][0] == "trailer"
&& current.res.status == 0
- greq:
grpctest.GrpcTestService/HelloChat:
Expand All @@ -66,7 +66,7 @@ steps:
request_time: "2022-06-25T05:24:43.861872Z"
- close
test: |
current.res.headers['content-type'][0] == 'application/grpc'
&& current.res.headers['hellochat'][0] == 'header'
current.res.headers['content-type'][0] == "application/grpc"
&& current.res.headers['hellochat'][0] == "header"
&& compare(current.res.messages[0], {"create_time":"2022-06-25T05:24:46.382783Z","message":"hello","num":34})
&& current.res.status == 0
18 changes: 9 additions & 9 deletions testdata/http.yml.runbook.golden
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ steps:
username: alice
test: |
current.res.status == 201
&& current.res.headers['Content-Length'][0] == '0'
&& current.res.headers['Content-Length'][0] == "0"
&& 'Date' in current.res.headers
&& current.res.rawBody == ""
- req:
Expand All @@ -24,7 +24,7 @@ steps:
name: bob
test: |
current.res.status == 201
&& current.res.headers['Content-Length'][0] == '0'
&& current.res.headers['Content-Length'][0] == "0"
&& 'Date' in current.res.headers
&& current.res.rawBody == ""
- req:
Expand All @@ -34,8 +34,8 @@ steps:
application/json: nil
test: |
current.res.status == 404
&& current.res.headers['Content-Length'][0] == '22'
&& current.res.headers['Content-Type'][0] == 'text/html; charset=utf-8'
&& current.res.headers['Content-Length'][0] == "22"
&& current.res.headers['Content-Type'][0] == "text/html; charset=utf-8"
&& 'Date' in current.res.headers
&& current.res.rawBody == "<h1>\n\"Not Found\"\n</h1>"
- req:
Expand All @@ -45,8 +45,8 @@ steps:
application/json: null
test: |
current.res.status == 200
&& current.res.headers['Content-Length'][0] == '29'
&& current.res.headers['Content-Type'][0] == 'application/json'
&& current.res.headers['Content-Length'][0] == "29"
&& current.res.headers['Content-Type'][0] == "application/json"
&& 'Date' in current.res.headers
&& compare(current.res.body, {"data":{"username":"alice"}})
- req:
Expand All @@ -56,8 +56,8 @@ steps:
application/json: null
test: |
current.res.status == 403
&& current.res.headers['Content-Length'][0] == '21'
&& current.res.headers['Content-Type'][0] == 'application/json'
&& current.res.headers['Content-Length'][0] == "21"
&& current.res.headers['Content-Type'][0] == "application/json"
&& 'Date' in current.res.headers
&& compare(current.res.body, {"error":"Forbidden"})
- req:
Expand All @@ -69,6 +69,6 @@ steps:
application/json: null
test: |
current.res.status == 200
&& current.res.headers['Content-Length'][0] == '0'
&& current.res.headers['Content-Length'][0] == "0"
&& 'Date' in current.res.headers
&& current.res.rawBody == ""