-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapi_test.go
39 lines (31 loc) · 1.04 KB
/
api_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
package slacker
import (
"bytes"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestAPIParsing(t *testing.T) {
Convey("API Response Parsing Utilities", t, func() {
Convey("When the response has failed", func() {
badResponse := `{"ok":false,"error":"not_authed"}`
dest := struct{}{}
err := ParseResponse(bytes.NewBufferString(badResponse), &dest)
So(err, ShouldEqual, ErrNotAuthed)
})
Convey("When the response has failed with an error we don't know about", func() {
badResponse := `{"ok":false,"error":"chicken"}`
dest := struct{}{}
err := ParseResponse(bytes.NewBufferString(badResponse), &dest)
So(err.Error(), ShouldEqual, "slacker: unknown error returned: chicken")
})
Convey("When the response is successful it decodes onto the destination", func() {
goodResponse := `{"ok":true,"hello":"world"}`
dest := &struct {
Hello string `json:"hello"`
}{}
err := ParseResponse(bytes.NewBufferString(goodResponse), dest)
So(err, ShouldBeNil)
So(dest.Hello, ShouldEqual, "world")
})
})
}