-
Notifications
You must be signed in to change notification settings - Fork 0
/
gores_test.go
66 lines (60 loc) · 1.62 KB
/
gores_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
package gores
import (
"errors"
"net/http"
"net/http/httptest"
"testing"
)
func dummyResult() map[string]interface{} {
return map[string]interface{}{
"keyString": "valueString",
"keyInt": 999,
"keyFloat": 20.6,
"keyFunc": []string{"one", "two", "three"},
}
}
const (
msgDumErr = "dummy error something"
)
func TestSuccess(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/", nil)
func(w http.ResponseWriter, r *http.Request) {
dataMap := dummyResult()
Success(dataMap, "success do something", http.StatusOK, w)
}(w, r)
}
func TestSuccessCreateOrUpdate(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodPost, "/", nil)
func(w http.ResponseWriter, r *http.Request) {
dataMap := dummyResult()
SuccessCreateOrUpdate(dataMap, "success create", w)
}(w, r)
}
func TestUnAuthorized(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/", nil)
func(w http.ResponseWriter, r *http.Request) {
err := errors.New(msgDumErr)
UnAuthorized(w, err)
}(w, r)
}
func TestError(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/", nil)
func(w http.ResponseWriter, r *http.Request) {
err := errors.New(msgDumErr)
Error(err, "error something", http.StatusInternalServerError, w)
}(w, r)
}
func TestErrorBool(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/", nil)
func(w http.ResponseWriter, r *http.Request) {
err := errors.New(msgDumErr)
if ErrorBool(err, "error name", http.StatusInternalServerError, w) {
return
}
}(w, r)
}