forked from AreaHQ/go-mailchimp
-
Notifications
You must be signed in to change notification settings - Fork 17
/
check_subscription_test.go
43 lines (35 loc) · 1.24 KB
/
check_subscription_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
package mailchimp_test
import (
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"testing"
mailchimp "github.com/RichardKnop/go-mailchimp"
"github.com/stretchr/testify/assert"
)
func TestCheckSubscriptionNotFoundError(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(404)
rw.Header().Set("Content-Type", "application/json")
fmt.Fprint(rw, notFoundErrorResponse)
}))
defer server.Close()
transport := &http.Transport{
Proxy: func(req *http.Request) (*url.URL, error) {
return url.Parse(server.URL)
},
}
client, err := mailchimp.NewClient("the_api_key-us13", &http.Client{Transport: transport})
assert.NoError(t, err)
baseURL, _ := url.Parse("http://localhost/")
client.SetBaseURL(baseURL)
memberResponse, err := client.CheckSubscription("list_id", "[email protected]")
assert.Nil(t, memberResponse)
assert.Equal(t, "Error 404 Resource Not Found (The requested resource could not be found.)", err.Error())
errResponse, ok := err.(*mailchimp.ErrorResponse)
assert.True(t, ok)
assert.Equal(t, "Resource Not Found", errResponse.Title)
assert.Equal(t, 404, errResponse.Status)
assert.Equal(t, "The requested resource could not be found.", errResponse.Detail)
}