-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaeolic_test.go
98 lines (77 loc) · 1.89 KB
/
aeolic_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
package aeolic
import (
_ "embed"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_parse_simple(t *testing.T) {
got, err := parse("basic", map[string]string{
"basic": `{ "hello": "{{ .hello }}" }`,
}, map[string]string{
"hello": "world",
})
assert.NoError(t, err)
assert.Equal(t, `{ "hello": "world" }`, string(got))
}
//go:embed examples/basic.tmpl.json
var embedTest string
func Test_parse_embed(t *testing.T) {
got, err := parse("basic", map[string]string{
"basic": embedTest,
}, map[string]string{
"user_name": "some-user-name",
})
assert.NoError(t, err)
assert.Contains(t, string(got), "some-user-name")
}
func Test_parse_missing_key(t *testing.T) {
_, err := parse("basic", map[string]string{
"basic": embedTest,
}, map[string]string{
"url_link": "some-link",
})
assert.Contains(t, err.Error(), "no entry for key \"user_name\" ")
}
func TestClient_SendMessage(t *testing.T) {
m := &httpClientMock{}
m.DoFunc = func(req *http.Request) (*http.Response, error) {
return &http.Response{
StatusCode: http.StatusOK,
}, nil
}
c := Client{
DefaultHeaders: map[string]string{
"": "",
},
Templates: map[string]string{
"basic": `{ "hello": "{{ .user_name }}" }`,
},
HTTPClient: m,
}
err := c.SendMessage("chan", "basic", map[string]string{
"user_name": "some-user-name",
})
assert.NoError(t, err)
}
func TestClient_SendMessage_api_error_should_return_error(t *testing.T) {
m := &httpClientMock{}
m.DoFunc = func(req *http.Request) (*http.Response, error) {
return &http.Response{
StatusCode: http.StatusInternalServerError,
}, nil
}
c := Client{
DefaultHeaders: map[string]string{
"": "",
},
Templates: map[string]string{
"basic": `{ "hello": "{{ .user_name }}" }`,
},
HTTPClient: m,
}
err := c.SendMessage("chan", "basic", map[string]string{
"user_name": "some-user-name",
})
assert.Error(t, err)
}