forked from ozontech/cute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilder_table.go
85 lines (66 loc) · 1.89 KB
/
builder_table.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
package cute
import "net/http"
func (qt *cute) CreateTableTest() MiddlewareTable {
qt.isTableTest = true
return qt
}
func (qt *cute) PutNewTest(name string, r *http.Request, expect *Expect) TableTest {
// Validate, that first step is empty
if qt.countTests == 0 {
if qt.tests[0].Request.Base == nil &&
len(qt.tests[0].Request.Builders) == 0 {
qt.tests[0].Expect = expect
qt.tests[0].Name = name
qt.tests[0].Request.Base = r
return qt
}
}
newTest := createDefaultTest(qt.baseProps)
newTest.Expect = expect
newTest.Name = name
newTest.Request.Base = r
qt.tests = append(qt.tests, newTest)
qt.countTests++ // async?
return qt
}
func (qt *cute) PutTests(tests ...*Test) TableTest {
for _, test := range tests {
// Fill common fields
qt.fillBaseProps(test)
// Validate, that first step is empty
if qt.countTests == 0 {
if qt.tests[0].Request.Base == nil &&
len(qt.tests[0].Request.Builders) == 0 {
qt.tests[0] = test
continue
}
}
qt.tests = append(qt.tests, test)
qt.countTests++
}
return qt
}
func (qt *cute) fillBaseProps(t *Test) {
if qt.baseProps == nil {
return
}
if qt.baseProps.httpClient != nil {
t.httpClient = qt.baseProps.httpClient
}
if qt.baseProps.jsonMarshaler != nil {
t.jsonMarshaler = qt.baseProps.jsonMarshaler
}
if t.Middleware == nil {
t.Middleware = createMiddlewareFromTemplate(qt.baseProps.middleware)
} else {
t.Middleware.After = append(t.Middleware.After, qt.baseProps.middleware.After...)
t.Middleware.AfterT = append(t.Middleware.AfterT, qt.baseProps.middleware.AfterT...)
t.Middleware.Before = append(t.Middleware.Before, qt.baseProps.middleware.Before...)
t.Middleware.BeforeT = append(t.Middleware.BeforeT, qt.baseProps.middleware.BeforeT...)
}
}
func (qt *cute) NextTest() NextTestBuilder {
qt.countTests++ // async?
qt.tests = append(qt.tests, createDefaultTest(qt.baseProps))
return qt
}