-
Notifications
You must be signed in to change notification settings - Fork 0
/
push_test.go
178 lines (146 loc) · 5.38 KB
/
push_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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package main
import (
"errors"
"fmt"
"math/rand"
"testing"
"time"
"github.com/Pilladian/go-helper"
)
// ------------------- Template -------------------
// func TestProcessData_EmptyID(t *testing.T) {
// rand.Seed(time.Now().UnixNano())
// initialize()
// // Input
// input := make(map[string]string)
// input["id"] = ""
// input["data"] = "{\"test\": \"test\"}"
// // Expectation
// ret_expect_01 := EXPECTATION_01
// ret_expect_02 := EXPECTATION_02
// // Run test
// ret_actual_01, ret_actual_02 := TESTING_PROCEDURE(input["id"], input["data"])
// // Evaluate test
// if ret_expect_01 == nil && ret_actual_01 == nil {
// // OK
// } else if ret_expect_01 == nil && ret_actual_01 != nil {
// t.Errorf(helper.Prettify("<nil>", ret_actual_01))
// } else if ret_expect_01 != nil && ret_actual_01 == nil {
// t.Errorf(helper.Prettify(ret_expect_01, "<nil>"))
// } else if ret_expect_01 != ret_actual_01 {
// t.Errorf(helper.Prettify(ret_expect_01, ret_actual_01))
// }
// if ret_expect_02 == nil && ret_actual_02 == nil {
// // OK
// } else if ret_expect_02 == nil && ret_actual_02 != nil {
// t.Errorf(helper.Prettify("<nil>", ret_actual_02))
// } else if ret_expect_02 != nil && ret_actual_02 == nil {
// t.Errorf(helper.Prettify(ret_expect_02, "<nil>"))
// } else if ret_expect_02 != ret_actual_02 {
// t.Errorf(helper.Prettify(ret_expect_02, ret_actual_02))
// }
// }
func TestProcessData_EmptyID(t *testing.T) {
rand.Seed(time.Now().UnixNano())
initialize()
// Input
input := make(map[string]string)
input["pid"] = ""
input["data"] = "{\"test\": \"test\"}"
// Expectation
ret_expect_01 := 801
ret_expect_02 := errors.New("Unrecognized pid format \"\"")
// Run test
ret_actual_01, ret_actual_02 := processData(input["pid"], input["data"])
// Evaluate test
if ret_expect_01 != ret_actual_01 {
t.Errorf(helper.Prettify(fmt.Sprint(ret_expect_01), fmt.Sprint(ret_actual_01)))
}
if ret_expect_02 == nil && ret_actual_02 == nil {
// OK
} else if ret_expect_02 == nil && ret_actual_02 != nil {
t.Errorf(helper.Prettify("<nil>", ret_actual_02.Error()))
} else if ret_expect_02 != nil && ret_actual_02 == nil {
t.Errorf(helper.Prettify(ret_expect_02.Error(), "<nil>"))
} else if ret_expect_02.Error() != ret_actual_02.Error() {
t.Errorf(helper.Prettify(ret_expect_02.Error(), ret_actual_02.Error()))
}
}
func TestProcessData_JSONParseError_01(t *testing.T) {
rand.Seed(time.Now().UnixNano())
initialize()
// Input
input := make(map[string]string)
input["id"] = "test_" + helper.RandomString(10)
input["data"] = "{\"test\": -}"
// Expectation
ret_expect_01 := 807
ret_expect_02 := errors.New("Provided json data {\"test\": -} could not be parsed : invalid character '}' in numeric literal")
// Run test
ret_actual_01, ret_actual_02 := processData(input["id"], input["data"])
// Evaluate test
if ret_expect_01 != ret_actual_01 {
t.Errorf(helper.Prettify(fmt.Sprint(ret_expect_01), fmt.Sprint(ret_actual_01)))
}
if ret_expect_02 == nil && ret_actual_02 == nil {
// OK
} else if ret_expect_02 == nil && ret_actual_02 != nil {
t.Errorf(helper.Prettify("<nil>", ret_actual_02.Error()))
} else if ret_expect_02 != nil && ret_actual_02 == nil {
t.Errorf(helper.Prettify(ret_expect_02.Error(), "<nil>"))
} else if ret_expect_02.Error() != ret_actual_02.Error() {
t.Errorf(helper.Prettify(ret_expect_02.Error(), ret_actual_02.Error()))
}
}
func TestProcessData_JSONParseError_02(t *testing.T) {
rand.Seed(time.Now().UnixNano())
initialize()
// Input
input := make(map[string]string)
input["id"] = "test_" + helper.RandomString(10)
input["data"] = "{\"test\": -, \"test2\": 444}"
// Expectation
ret_expect_01 := 807
ret_expect_02 := errors.New("Provided json data {\"test\": -, \"test2\": 444} could not be parsed : invalid character ',' in numeric literal")
// Run test
ret_actual_01, ret_actual_02 := processData(input["id"], input["data"])
// Evaluate test
if ret_expect_01 != ret_actual_01 {
t.Errorf(helper.Prettify(fmt.Sprint(ret_expect_01), fmt.Sprint(ret_actual_01)))
}
if ret_expect_02 == nil && ret_actual_02 == nil {
// OK
} else if ret_expect_02 == nil && ret_actual_02 != nil {
t.Errorf(helper.Prettify("<nil>", ret_actual_02.Error()))
} else if ret_expect_02 != nil && ret_actual_02 == nil {
t.Errorf(helper.Prettify(ret_expect_02.Error(), "<nil>"))
} else if ret_expect_02.Error() != ret_actual_02.Error() {
t.Errorf(helper.Prettify(ret_expect_02.Error(), ret_actual_02.Error()))
}
}
func TestProcessData_JSONParseError_03(t *testing.T) {
rand.Seed(time.Now().UnixNano())
initialize()
// Input
input := make(map[string]string)
input["id"] = "test_" + helper.RandomString(10)
input["data"] = "{\"test\": \"-\", \"test2\": 444}"
// Expectation
ret_expect_01 := 0
var ret_expect_02 error
// Run test
ret_actual_01, ret_actual_02 := processData(input["id"], input["data"])
// Evaluate test
if ret_expect_01 != ret_actual_01 {
t.Errorf(helper.Prettify(fmt.Sprint(ret_expect_01), fmt.Sprint(ret_actual_01)))
}
if ret_expect_02 == nil && ret_actual_02 == nil {
// OK
} else if ret_expect_02 == nil && ret_actual_02 != nil {
t.Errorf(helper.Prettify("<nil>", ret_actual_02.Error()))
} else if ret_expect_02 != nil && ret_actual_02 == nil {
t.Errorf(helper.Prettify(ret_expect_02.Error(), "<nil>"))
} else if ret_expect_02.Error() != ret_actual_02.Error() {
t.Errorf(helper.Prettify(ret_expect_02.Error(), ret_actual_02.Error()))
}
}