Repository navigation
Expand file tree
/
Copy pathinput_test.go
More file actions
141 lines (112 loc) · 3.3 KB
/
Copy pathinput_test.go
File metadata and controls
141 lines (112 loc) · 3.3 KB
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
package httper
import (
"net/http"
"net/http/httptest"
"reflect"
"testing"
)
func TestInt64(t *testing.T) {
r := httptest.NewRequest(http.MethodGet, "/testing?test=42", nil)
w := httptest.NewRecorder()
test, err := CheckFormInt64(r, w, "test")
if err != nil || test != 42 || reflect.TypeOf(test).Kind() != reflect.Int64 {
t.Fatalf("Error read int64 %v", err)
}
res := w.Result()
defer res.Body.Close()
if res.StatusCode != 200 {
t.Fatalf("Expected status code 200")
}
}
func TestInt(t *testing.T) {
r := httptest.NewRequest(http.MethodGet, "/testing?test=42", nil)
w := httptest.NewRecorder()
test, err := CheckFormInt(r, w, "test")
if err != nil || test != 42 || reflect.TypeOf(test).Kind() != reflect.Int {
t.Fatalf("Error read int %v", err)
}
res := w.Result()
defer res.Body.Close()
if res.StatusCode != 200 {
t.Fatalf("Expected status code 200")
}
}
func TestString(t *testing.T) {
r := httptest.NewRequest(http.MethodGet, "/testing?test=kexxu", nil)
w := httptest.NewRecorder()
test, err := CheckFormString(r, w, "test")
if err != nil || test != "kexxu" || reflect.TypeOf(test).Kind() != reflect.String {
t.Fatalf("Error read string %v", err)
}
res := w.Result()
defer res.Body.Close()
if res.StatusCode != 200 {
t.Fatalf("Expected status code 200")
}
}
func TestInt64Wrong(t *testing.T) {
// invalid
r := httptest.NewRequest(http.MethodGet, "/testing?test=wrong", nil)
w := httptest.NewRecorder()
_, err := CheckFormInt64(r, w, "test")
if err == nil {
t.Fatalf("Error read wrong int64, should give an error")
}
res := w.Result()
defer res.Body.Close()
if res.StatusCode != 400 {
t.Fatalf("Was a wrong value, should return status 400 but returned %d", res.StatusCode)
}
// missing
r = httptest.NewRequest(http.MethodGet, "/testing", nil)
w = httptest.NewRecorder()
_, err = CheckFormInt64(r, w, "test")
if err == nil {
t.Fatalf("Error read wrong int64, should give an error")
}
res2 := w.Result()
defer res2.Body.Close()
if res2.StatusCode != 400 {
t.Fatalf("Was a wrong value, should return status 400 but returned %d", res2.StatusCode)
}
}
func TestIntWrong(t *testing.T) {
// invalid
r := httptest.NewRequest(http.MethodGet, "/testing?test=wrong", nil)
w := httptest.NewRecorder()
_, err := CheckFormInt(r, w, "test")
if err == nil {
t.Fatalf("Error read wrong int, should give an error")
}
res := w.Result()
defer res.Body.Close()
if res.StatusCode != 400 {
t.Fatalf("Was a wrong value, should return status 400 but returned %d", res.StatusCode)
}
// missing
r = httptest.NewRequest(http.MethodGet, "/testing", nil)
w = httptest.NewRecorder()
_, err = CheckFormInt(r, w, "test")
if err == nil {
t.Fatalf("Error read wrong int, should give an error")
}
res2 := w.Result()
defer res2.Body.Close()
if res2.StatusCode != 400 {
t.Fatalf("Was a wrong value, should return status 400 but returned %d", res2.StatusCode)
}
}
func TestStringWrong(t *testing.T) {
// missing
r := httptest.NewRequest(http.MethodGet, "/testing", nil)
w := httptest.NewRecorder()
_, err := CheckFormString(r, w, "test")
if err == nil {
t.Fatalf("Error read wrong string, should give an error")
}
res2 := w.Result()
defer res2.Body.Close()
if res2.StatusCode != 400 {
t.Fatalf("Was a wrong value, should return status 400 but returned %d", res2.StatusCode)
}
}