coder / hat

HTTP API testing for Go
MIT License
36 stars 3 forks source link

Feature/t helper #23

Closed coadler closed 6 years ago

coadler commented 6 years ago

This pr allows t.Logs in RequestOptions and ResponseAssertions to show the line number of the test they are called from instead of an arbitrary line number from inside hat.

Before

request.go:91: PATCH /organizations/7811201446115661389/members/accounts/7811201446215032237 HTTP/1.1
    Host: 127.0.0.1:42629
    User-Agent: Go-http-client/1.1
    Transfer-Encoding: chunked
    Api-Key: mHmXoHKbACnpWshkUVsr
    Accept-Encoding: gzip

    21
    {"op":"add","nodes":"roster.add"}
    0

request.go:76: PATCH http://127.0.0.1:42629/organizations/7811201446115661389/members/accounts/7811201446215032237
response.go:36: body:
    HTTP/1.1 200 OK
    Content-Length: 107
    Access-Control-Allow-Credentials: true
    Content-Type: application/json
    Date: Thu, 07 Jun 2018 23:19:47 GMT
    Request-Id: 5b19bd93-16fd418a6326acf1199047bd
    Rl-Bucket: long
    Rl-Capacity: 60000
    Rl-Level: 100
    Version: wapi-integration-testing

    {"id":7811201446215032237,"id_str":"7811201446215032237","msg":"Account permissions successfully updated."}

After

organizations_intg_test.go:436: PATCH /organizations/7811087887164865469/members/accounts/7811087887223200829 HTTP/1.1
    Host: 127.0.0.1:43201
    User-Agent: Go-http-client/1.1
    Transfer-Encoding: chunked
    Api-Key: a8fkWwTHbPHtPxDHcVu0
    Accept-Encoding: gzip

    21
    {"op":"add","nodes":"roster.add"}
    0

organizations_intg_test.go:444: PATCH http://127.0.0.1:43201/organizations/7811087887164865469/members/accounts/7811087887223200829
organizations_intg_test.go:444: body:
    HTTP/1.1 200 OK
    Content-Length: 107
    Access-Control-Allow-Credentials: true
    Content-Type: application/json
    Date: Thu, 07 Jun 2018 21:29:37 GMT
    Request-Id: 5b19a3c1-4cb34acfe89ca89041ec49bd
    Rl-Bucket: long
    Rl-Capacity: 60000
    Rl-Level: 100
    Version: wapi-integration-testing

    {"id":7811087887223200829,"id_str":"7811087887223200829","msg":"Account permissions successfully updated."}
coadler commented 6 years ago

Error traces will need some more rethinking. I wasn't able to get rid of the references inside of hat

Example:

Error Trace:    status.go:14
                response.go:36
                organizations_intg_test.go:444
                organizations_intg_test.go:71
                hat.go:50
Error:          Not equal: 
                expected: 132
                actual  : 200
nhooyr commented 6 years ago

@ThyLeader thats fine imo because you get a complete stack trace so its easy to figure out the original call.

ammario commented 6 years ago

Good to merge after commits are squashed.