-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchannel_token_test.go
68 lines (62 loc) · 1.62 KB
/
channel_token_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
package authorizer_test
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
"github.com/kutsuzawa/line-authorizer"
)
func TestChannelToken_Publish(t *testing.T) {
t.Helper()
t.Run("Successful publishing channel token", func(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/v2/oauth/accessToken" {
w.WriteHeader(http.StatusNotFound)
return
}
b, _ := ioutil.ReadFile("testdata/channel_auth_token.json")
w.Write(b)
return
},
))
defer ts.Close()
config := authorizer.Config{
APIAddress: ts.URL,
}
client := authorizer.NewClient(config)
token, err := client.PublishChannelToken()
if err != nil {
t.Errorf("err shoud not occur, but err: %v", err)
}
if *token != "W1TeHCgfH2Liwa" {
t.Errorf("token should be %s, but actual is %s", "W1TeHCgfH2Liwa", *token)
}
})
t.Run("Failed publishing channel token", func(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/v2/oauth/accessToken" {
w.WriteHeader(http.StatusNotFound)
return
}
b, _ := ioutil.ReadFile("testdata/channel_auth_token_err.json")
w.WriteHeader(http.StatusBadRequest)
w.Write(b)
return
},
))
defer ts.Close()
config := authorizer.Config{
APIAddress: ts.URL,
}
client := authorizer.NewClient(config)
token, err := client.PublishChannelToken()
if token != nil {
t.Errorf("token should be nil, but actual is %v", token)
}
if err == nil {
t.Errorf("err shoud occur, but it does not")
}
})
}