-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtable_test.go
154 lines (142 loc) · 3.35 KB
/
table_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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//go:build example
// +build example
package table_test
import (
"context"
"fmt"
"net/http"
"net/url"
"os"
"testing"
"github.com/ozontech/cute"
"github.com/ozontech/cute/asserts/json"
"github.com/ozontech/cute/errors"
)
func init() {
os.Setenv("ALLURE_OUTPUT_PATH", "../") // custom, read Readme.md for more info
}
func Test_Table(t *testing.T) {
u, _ := url.Parse("https://jsonplaceholder.typicode.com/posts/1/comments")
req, _ := http.NewRequest(http.MethodPost, u.String(), nil)
req.Header = map[string][]string{
"some_auth_token": []string{fmt.Sprint(11111)},
}
cute.NewTestBuilder().
Title("Example put tests in table test").
Tag("table_test").
CreateTableTest().
PutNewTest(
"Execute validation 1",
req,
&cute.Expect{
Code: 201,
}).
PutNewTest(
"Execute validation 2",
req,
&cute.Expect{
AssertBody: []cute.AssertBody{
json.Equal("$[0].email", "[email protected]"),
json.Present("$[1].name"),
},
},
).
ExecuteTest(context.Background(), t)
}
func Test_Table_Array(t *testing.T) {
tests := []*cute.Test{
{
Name: "Create something",
Middleware: nil,
Request: &cute.Request{
Builders: []cute.RequestBuilder{
cute.WithURI("https://jsonplaceholder.typicode.com/posts/1/comments"),
cute.WithMethod(http.MethodPost),
},
},
Expect: &cute.Expect{
Code: 200,
},
},
{
Name: "Delete something",
Middleware: nil,
Request: &cute.Request{
Builders: []cute.RequestBuilder{
cute.WithURI("https://jsonplaceholder.typicode.com/posts/1/comments"),
cute.WithMethod(http.MethodGet),
},
},
Expect: &cute.Expect{
Code: 200,
AssertBody: []cute.AssertBody{
json.Equal("$[0].email", "[email protected]"),
json.Present("$[1].name"),
func(body []byte) error {
return errors.NewAssertError("example error", "example message", nil, nil)
},
},
},
},
}
cute.NewTestBuilder().
Title("Example table test").
Tag("table_test").
Description("Execute array tests").
CreateTableTest().
PutTests(tests...).
ExecuteTest(context.Background(), t)
}
func Test_One_Execute(t *testing.T) {
test := &cute.Test{
Name: "test_1",
Request: &cute.Request{
Builders: []cute.RequestBuilder{
cute.WithURI("https://jsonplaceholder.typicode.com/posts/1/comments"),
cute.WithMethod(http.MethodGet),
},
},
Expect: nil,
}
test.Execute(context.Background(), t)
}
func Test_Array(t *testing.T) {
tests := []*cute.Test{
{
Name: "test_1",
Middleware: nil,
Request: &cute.Request{
Builders: []cute.RequestBuilder{
cute.WithURI("https://jsonplaceholder.typicode.com/posts/1/comments"),
cute.WithMethod(http.MethodPost),
},
},
Expect: &cute.Expect{
Code: 200,
},
},
{
Name: "test_2",
Middleware: nil,
Request: &cute.Request{
Builders: []cute.RequestBuilder{
cute.WithURI("https://jsonplaceholder.typicode.com/posts/1/comments"),
cute.WithMethod(http.MethodGet),
},
},
Expect: &cute.Expect{
Code: 200,
AssertBody: []cute.AssertBody{
json.Equal("$[0].email", "[email protected]"),
json.Present("$[1].name"),
func(body []byte) error {
return errors.NewAssertError("example error", "example message", nil, nil)
},
},
},
},
}
for _, test := range tests {
test.Execute(context.Background(), t)
}
}