/
doc_test.go
86 lines (71 loc) · 1.88 KB
/
doc_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package frisby_test
import (
"fmt"
"reflect"
"github.com/bitly/go-simplejson"
"github.com/verdverm/frisby"
)
func init() {
frisby.Global.PrintProgressDot = false
}
func ExampleFrisby_Get() {
frisby.Create("Test GET Go homepage").
Get("http://golang.org").
Send().
ExpectStatus(200).
ExpectContent("The Go Programming Language").
PrintReport()
// Output: Pass [Test GET Go homepage]
}
func ExampleFrisby_Post() {
frisby.Create("Test POST").
Post("http://httpbin.org/post").
SetData("test_key", "test_value").
Send().
ExpectStatus(200).
PrintReport()
// Output: Pass [Test POST]
}
func ExampleFrisby_PrintReport() {
frisby.Create("Test GET Go homepage").
Get("http://golang.org").
Send().
ExpectStatus(400).
ExpectContent("A string which won't be found").
AddError("Manually Added Error").
PrintReport()
// Output: FAIL [Test GET Go homepage]
// - Expected Status 400, but got 200: "200 OK"
// - Expected Body to contain "A string which won't be found", but it was missing
// - Manually Added Error
}
func ExampleFrisby_ExpectJsonType() {
frisby.Create("Test ExpectJsonType").
Post("http://httpbin.org/post").
Send().
ExpectStatus(200).
ExpectJsonType("url", reflect.String).
PrintReport()
// Output: Pass [Test ExpectJsonType]
}
func ExampleFrisby_ExpectJson() {
frisby.Create("Test ExpectJson").
Post("http://httpbin.org/post").
Send().
ExpectStatus(200).
ExpectJson("url", "http://httpbin.org/post").
ExpectJson("headers.Accept", "*/*").
PrintReport()
// Output: Pass [Test ExpectJson]
}
func ExampleFrisby_AfterJson() {
frisby.Create("Test AfterJson").
Post("http://httpbin.org/post").
Send().
ExpectStatus(200).
AfterJson(func(F *frisby.Frisby, json *simplejson.Json, err error) {
val, _ := json.Get("url").String()
fmt.Println("url =", val)
})
// Output: url = http://httpbin.org/post
}