-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
44 lines (34 loc) · 962 Bytes
/
main_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
package main
import (
"net/http"
"testing"
"github.com/aws/aws-lambda-go/events"
)
func TestHandler(t *testing.T) {
prepare()
tests := []struct {
label, owner, repo, method string
status int
}{
{"normal", "toshi0607", "gig", "POST", http.StatusOK},
{"invalid req", "", "gig", "POST", http.StatusBadRequest},
{"invalid repo", "toshi0607", "nothing", "POST", http.StatusInternalServerError},
{"invalid method", "toshi0607", "gig", "GET", http.StatusBadRequest},
}
for _, te := range tests {
res, _ := handler(events.APIGatewayProxyRequest{
HTTPMethod: te.method,
Body: "{\"owner\": \"" + te.owner + "\", \"repo\": \"" + te.repo + "\"}",
})
if res.StatusCode != te.status {
t.Errorf("ExitStatus=%d, want %d", res.StatusCode, te.status)
}
}
}
func prepare() {
twitterClient = mockClient("mock")
}
type mockClient string
func (m mockClient) Tweet(s string) (string, error) {
return s, nil
}