package dethnote_test import ( "testing" dethnote "git.kirsle.net/apps/dethnote/src" ) func TestParseSMTPUrl(t *testing.T) { type testPair struct { url string expect dethnote.MailConfig } tests := []testPair{ testPair{ url: "localhost:25", expect: dethnote.MailConfig{ Hostname: "localhost", Port: 25, }, }, testPair{ url: "ssl://mail.example.com:465", expect: dethnote.MailConfig{ Hostname: "mail.example.com", Port: 465, SSL: true, }, }, testPair{ url: "user:pass@localhost:25", expect: dethnote.MailConfig{ Username: "user", Password: "pass", Hostname: "localhost", Port: 25, }, }, testPair{ url: "smtps://user:pass@mail.example.com", expect: dethnote.MailConfig{ Hostname: "mail.example.com", Port: 465, Username: "user", Password: "pass", SSL: true, }, }, testPair{ url: "localhost", expect: dethnote.MailConfig{ Hostname: "localhost", Port: 25, }, }, } for _, test := range tests { actual, _ := dethnote.ParseSMTPUrl(test.url) if actual != test.expect { t.Errorf( "Unexpected parsing of SMTP URL\n"+ "URL: %s\n"+ "Expect: %+v\n"+ "Actual: %+v", test.url, test.expect, actual, ) } } }