This repository has been archived on 2022-08-17. You can view files and clone it, but cannot push or open issues or pull requests.
dex/vendor/github.com/mailgun/mailgun-go/mailgun_test.go

79 lines
1.4 KiB
Go
Raw Normal View History

2016-04-09 00:26:29 +05:30
package mailgun
import (
2016-06-28 22:48:18 +05:30
"net/http"
2016-04-09 00:26:29 +05:30
"strconv"
"testing"
)
const domain = "valid-mailgun-domain"
const apiKey = "valid-mailgun-api-key"
const publicApiKey = "valid-mailgun-public-api-key"
func TestMailgun(t *testing.T) {
m := NewMailgun(domain, apiKey, publicApiKey)
if domain != m.Domain() {
t.Fatal("Domain not equal!")
}
if apiKey != m.ApiKey() {
t.Fatal("ApiKey not equal!")
}
if publicApiKey != m.PublicApiKey() {
t.Fatal("PublicApiKey not equal!")
}
2016-06-28 22:48:18 +05:30
if http.DefaultClient != m.Client() {
t.Fatal("HTTP client not default!")
}
client := new(http.Client)
m.SetClient(client)
if client != m.Client() {
t.Fatal("HTTP client not equal!")
}
2016-04-09 00:26:29 +05:30
}
func TestBounceGetCode(t *testing.T) {
b1 := &Bounce{
CreatedAt: "blah",
code: 123,
Address: "blort",
Error: "bletch",
}
c, err := b1.GetCode()
if err != nil {
t.Fatal(err)
}
if c != 123 {
t.Fatal("Expected 123; got ", c)
}
b2 := &Bounce{
CreatedAt: "blah",
code: "456",
Address: "blort",
Error: "Bletch",
}
c, err = b2.GetCode()
if err != nil {
t.Fatal(err)
}
if c != 456 {
t.Fatal("Expected 456; got ", c)
}
b3 := &Bounce{
CreatedAt: "blah",
code: "456H",
Address: "blort",
Error: "Bletch",
}
c, err = b3.GetCode()
e, ok := err.(*strconv.NumError)
if !ok && e != nil {
t.Fatal("Expected a syntax error in numeric conversion: got ", err)
}
}