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/email/mailgun_test.go
Bobby Rullo c94e53846e email: templatizer takes global context.
This is so we can populate emails with things like the issuer name.
2015-10-30 14:53:52 -07:00

56 lines
1.3 KiB
Go

package email
import (
"strings"
"testing"
"github.com/kylelemons/godebug/pretty"
)
func TestNewEmailConfigFromReader(t *testing.T) {
tests := []struct {
json string
want MailgunEmailerConfig
wantErr bool
}{
{
json: `{"type":"mailgun","id":"mg","privateAPIKey":"private","publicAPIKey":"public","domain":"example.com"}`,
want: MailgunEmailerConfig{
PrivateAPIKey: "private",
PublicAPIKey: "public",
Domain: "example.com",
},
},
{
json: `{"type":"mailgun","id":"mg","publicAPIKey":"public","domain":"example.com"}`,
wantErr: true,
},
{
json: `{"type":"mailgun","id":"mg","privateAPIKey":"private","publicAPIKey":"public"}`,
wantErr: true,
},
{
json: `{"type":"mailgun","id":"mg","privateAPIKey":"private","domain":"example.com"}`,
wantErr: true,
},
}
for i, tt := range tests {
r := strings.NewReader(tt.json)
ec, err := newEmailerConfigFromReader(r)
if tt.wantErr {
if err == nil {
t.Errorf("case %d: want non-nil err.", i)
}
t.Logf("WHAT: %v", err)
continue
}
if err != nil {
t.Errorf("case %d: want nil err: %v", i, err)
continue
}
if diff := pretty.Compare(tt.want, ec); diff != "" {
t.Errorf("case %d: Compare(want, got): %v", i, diff)
}
}
}