OpenID Connect (OIDC) identity and OAuth 2.0 provider with pluggable connectors
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

56 lines
1.3 KiB

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)
}
}
}