-
Notifications
You must be signed in to change notification settings - Fork 1
/
response_test.go
63 lines (51 loc) · 1.3 KB
/
response_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
package easycodefgo
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
// newResponseByMessage 테스트
func TestNewResponseByMessage(t *testing.T) {
ast := assert.New(t)
res := newResponseByMessage(messageNotFound)
data := res.GetData()
ast.NotNil(data)
result := res.GetResult()
ast.NotNil(result)
testResponseGetMessageInfo(ast, res, messageNotFound)
}
// Response.GetMessageInfo 테스트
func testResponseGetMessageInfo(
ast *assert.Assertions,
res *Response,
m *messageConstant,
) {
code, msg, extraMsg := res.GetMessageInfo()
ast.Equal(m.Code, code)
ast.Equal(m.Message, msg)
ast.Equal(m.ExtraMessage, extraMsg)
}
// newResponseByMap 테스트
func TestNewResponseByMap(t *testing.T) {
ast := assert.New(t)
m := map[string]interface{}{
KeyResult: make(map[string]interface{}),
KeyData: make([]map[string]interface{}, 1),
}
res := newResponseByMap(m)
ast.NotNil(res)
}
// Response 인스턴스를 JSON string으로 변환 테스트
func TestWriteValueAsString(t *testing.T) {
ast := assert.New(t)
res := newResponseByMessage(messageOK)
str := res.WriteValueAsString()
// 원하는 결과
s := fmt.Sprintf(
`{"data":{},"result":{"code":"%s","extraMessage":"%s","message":"%s"}}`,
messageOK.Code,
messageOK.ExtraMessage,
messageOK.Message,
)
ast.Equal(str, s)
}