This reduces a lot of duplictaive expressions in tests.
responseOK(t, conn)
ok(t, conn.PrintfLine("STAT"))
- line = responseOK(t, conn)
- expected := "+OK 2 320"
- if line != expected {
- t.Errorf("STAT expected %q, got %q", expected, line)
+ if want, got := "+OK 2 320", responseOK(t, conn); want != got {
+ t.Errorf("STAT want %q, got %q", want, got)
}
ok(t, conn.PrintfLine("LIST"))
responseOK(t, conn)
lines, err := conn.ReadDotLines()
ok(t, err)
- if len(lines) != 2 {
- t.Errorf("LIST expected 2 lines, got %d", len(lines))
+ if want, got := 2, len(lines); want != got {
+ t.Errorf("LIST want %d lines, got %d", want, got)
}
- expected = "1 120"
- if lines[0] != expected {
- t.Errorf("LIST line 0 expected %q, got %q", expected, lines[0])
+ if want, got := "1 120", lines[0]; want != got {
+ t.Errorf("LIST line 0 want %q, got %q", want, got)
}
- expected = "2 200"
- if lines[1] != expected {
- t.Errorf("LIST line 1 expected %q, got %q", expected, lines[1])
+ if want, got := "2 200", lines[1]; want != got {
+ t.Errorf("LIST line 1 expected %q, got %q", want, got)
}
ok(t, conn.PrintfLine("QUIT"))
return ""
}
- expected := []string{"hello"}
- if !reflect.DeepEqual(resp, expected) {
- t.Errorf("Expected %v, got %v", expected, resp)
+ want := []string{"hello"}
+ if !reflect.DeepEqual(resp, want) {
+ t.Errorf("Want %v, got %v", want, resp)
}
return ""
return ""
}
- expected := []string{"this", "is a", ".", "test"}
- if !reflect.DeepEqual(resp, expected) {
- t.Errorf("Expected %v, got %v", expected, resp)
+ want := []string{"this", "is a", ".", "test"}
+ if !reflect.DeepEqual(resp, want) {
+ t.Errorf("Want %v, got %v", want, resp)
}
return ""
return ""
}
- expected := []string{
+ want := []string{
fmt.Sprintf("1 %p", s.mb.msgs[1]),
fmt.Sprintf("3 %p", s.mb.msgs[3]),
}
- if !reflect.DeepEqual(resp, expected) {
- t.Errorf("Expected %v, got %v", expected, resp)
+ if !reflect.DeepEqual(resp, want) {
+ t.Errorf("Want %v, got %v", want, resp)
}
return ""
}
for i, c := range cases {
mb, err := s.OpenMailbox(c.user, c.pass)
- actual := (mb != nil && err == nil)
- if actual != c.ok {
- t.Errorf("Expected error=%v for case %d (%#v), got %v (error=%v, mb=%v)", c.ok, i, c, actual, err, mb)
+ got := (mb != nil && err == nil)
+ if got != c.ok {
+ t.Errorf("Expected error=%v for case %d (%#v), got %v (error=%v, mb=%v)", c.ok, i, c, got, err, mb)
}
}
}
_, err = conn.ReadLine()
if err != nil {
- t.Errorf("Failed to read line: %v\n", err)
+ t.Errorf("Failed to read line: %v", err)
return
}
}
t.Errorf("Failed to list messages: %v", err)
}
- if len(msgs) != 2 {
- t.Errorf("Expected 2 messages, got %d", len(msgs))
+ if want, got := 2, len(msgs); want != got {
+ t.Errorf("Want %d messages, got %d", want, got)
}
if mb.GetMessage(0) != nil {
t.Errorf("Failed to look up message by ID")
}
- if msgs[0].UniqueID() != "a" {
- t.Errorf("Expected message #1 unique ID to be a, got %s", msgs[0].UniqueID())
+ if want, got := "a", msgs[0].UniqueID(); want != got {
+ t.Errorf("Want message #1 unique ID to be %s, got %s", want, got)
}
- expectedSize := 1024 * 10
- if msgs[0].Size() != expectedSize {
- t.Errorf("Expected message #1 size to be %v, got %v", expectedSize, msgs[0].Size())
+ if want, got := 1024*10, msgs[0].Size(); want != got {
+ t.Errorf("Want message #1 size to be %v, got %v", want, got)
}
- if msgs[1].UniqueID() != "b" {
- t.Errorf("Expected message #2 unique ID to be b, got %s", msgs[0].UniqueID())
+ if want, got := "b", msgs[1].UniqueID(); want != got {
+ t.Errorf("Want message #2 unique ID to be %s, got %s", want, got)
}
- expectedSize = 1024 * 3
- if msgs[1].Size() != expectedSize {
- t.Errorf("Expected message #2 size to be %v, got %v", expectedSize, msgs[0].Size())
+ if want, got := 1024*3, msgs[1].Size(); want != got {
+ t.Errorf("Want message #2 size to be %v, got %v", want, got)
}
// Test message contents.
t.Errorf("Failed to list messages: %v", err)
}
- if len(msgs) != 1 {
- t.Errorf("Number of messages should be 1, got %d", len(msgs))
+ if want, got := 1, len(msgs); want != got {
+ t.Errorf("Number of messages should be %d, got %d", want, got)
}
- if msgs[0].UniqueID() != "b" {
- t.Errorf("Message Unique ID should be b, got %s", msgs[0].UniqueID())
+ if want, got := "b", msgs[0].UniqueID(); want != got {
+ t.Errorf("Message Unique ID should be %s, got %s", want, got)
}
}
actual := conn.getReceivedInfo(envelope)
actualLines := strings.SplitAfter(string(actual), crlf)
- if len(actualLines) != len(test.expect) {
- t.Errorf("wrong numbber of lines, expected %d, got %d", len(test.expect), len(actualLines))
+ if want, got := len(test.expect), len(actualLines); want != got {
+ t.Errorf("wrong numbber of lines, want %d, got %d", want, got)
continue
}
for i, line := range actualLines {
- expect := test.expect[i]
- if expect != strings.TrimLeft(line, " ") {
- t.Errorf("Expected equal string %q, got %q", expect, line)
+ if want, got := test.expect[i], strings.TrimLeft(line, " "); want != got {
+ t.Errorf("want equal string %q, got %q", want, got)
}
}
}
}},
})
- if len(server.relayed) != 1 {
- t.Errorf("Expected 1 relayed message, got %d", len(server.relayed))
+ if want, got := 1, len(server.relayed); want != got {
+ t.Errorf("Want %d relayed message, got %d", want, got)
}
}
}},
})
- if len(server.relayed) != 1 {
- t.Fatalf("Expected 1 relayed message, got %d", len(server.relayed))
+ if want, got := 1, len(server.relayed); want != got {
+ t.Fatalf("Want %d relayed message, got %d", want, got)
}
replaced := "source@example.com"
original := "mailbox@example.com"
en := server.relayed[0]
- if en.MailFrom.Address != replaced {
- t.Errorf("Expected mail to be from %q, got %q", replaced, en.MailFrom.Address)
+ if want, got := replaced, en.MailFrom.Address; want != got {
+ t.Errorf("Want mail to be from %q, got %q", want, got)
}
- if len(en.RcptTo) != 1 {
- t.Errorf("Expected 1 recipient, got %d", len(en.RcptTo))
+ if want, got := 1, len(en.RcptTo); want != got {
+ t.Errorf("Want %d recipient, got %d", want, got)
}
- if en.RcptTo[0].Address != "valid@dest.xyz" {
- t.Errorf("Unexpected RcptTo %q", en.RcptTo[0].Address)
+ if want, got := "valid@dest.xyz", en.RcptTo[0].Address; want != got {
+ t.Errorf("Unexpected RcptTo %q", got)
}
msg := string(en.Data)
original := "mailbox@example.com"
en := server.relayed[0]
- if en.MailFrom.Address != replaced {
- t.Errorf("Expected mail to be from %q, got %q", replaced, en.MailFrom.Address)
+ if want, got := replaced, en.MailFrom.Address; want != got {
+ t.Errorf("Want mail to be from %q, got %q", want, got)
}
- if len(en.RcptTo) != 2 {
- t.Errorf("Expected 2 recipient, got %d", len(en.RcptTo))
+ if want, got := 2, len(en.RcptTo); want != got {
+ t.Errorf("Want %d recipients, got %d", want, got)
}
- if en.RcptTo[0].Address != "valid@dest.xyz" {
- t.Errorf("Unexpected RcptTo %q", en.RcptTo[0].Address)
+ if want, got := "valid@dest.xyz", en.RcptTo[0].Address; want != got {
+ t.Errorf("Unexpected RcptTo %q", got)
}
msg := string(en.Data)
host, port, _ := net.SplitHostPort(l.Addr().String())
relayMessageToHost(s, env, zap.NewNop(), env.RcptTo[0].Address, host, port)
- if len(s.messages) != 1 {
- t.Errorf("Expected 1 message to be delivered, got %d", len(s.messages))
+ if want, got := 1, len(s.messages); want != got {
+ t.Errorf("Want %d message to be delivered, got %d", want, got)
return
}
received := s.messages[0]
- if env.MailFrom.Address != received.MailFrom.Address {
- t.Errorf("Expected MailFrom %s, got %s", env.MailFrom.Address, received.MailFrom.Address)
+ if want, got := env.MailFrom.Address, received.MailFrom.Address; want != got {
+ t.Errorf("Want MailFrom %s, got %s", want, got)
}
- if len(received.RcptTo) != 1 {
- t.Errorf("Expected 1 RcptTo, got %d", len(received.RcptTo))
+ if want, got := 1, len(received.RcptTo); want != got {
+ t.Errorf("Want %d RcptTo, got %d", want, got)
return
}
- if env.RcptTo[0].Address != received.RcptTo[0].Address {
- t.Errorf("Expected RcptTo %s, got %s", env.RcptTo[0].Address, received.RcptTo[0].Address)
+ if want, got := env.RcptTo[0].Address, received.RcptTo[0].Address; want != got {
+ t.Errorf("Want RcptTo %s, got %s", want, got)
}
if !bytes.HasSuffix(received.Data, env.Data) {
errorStr2 := "general error 122"
deliverRelayFailure(s, env, zap.NewNop(), env.RcptTo[0].Address, errorStr1, fmt.Errorf(errorStr2))
- if len(s.messages) != 1 {
- t.Errorf("Expected 1 failure notification, got %d", len(s.messages))
+ if want, got := 1, len(s.messages); want != got {
+ t.Errorf("Want %d failure notification, got %d", want, got)
return
}
failure := s.messages[0]
- if failure.RcptTo[0].Address != env.MailFrom.Address {
- t.Errorf("Failure message should be delivered to sender %s, actually %s", env.MailFrom.Address, failure.RcptTo[0].Address)
+ if want, got := env.MailFrom.Address, failure.RcptTo[0].Address; want != got {
+ t.Errorf("Failure message should be delivered to sender %s, actually %s", want, got)
}
// Read the failure message.
return
}
- expected := "multipart/report"
- if mediatype != expected {
- t.Errorf("Expected MIME type of %q, got %q", expected, mediatype)
+ if want, got := "multipart/report", mediatype; want != got {
+ t.Errorf("Want MIME type of %q, got %q", want, got)
}
- expected = "delivery-status"
- if mtheaders["report-type"] != expected {
- t.Errorf("Expected report-type of %q, got %q", expected, mtheaders["report-type"])
+ if want, got := "delivery-status", mtheaders["report-type"]; want != got {
+ t.Errorf("Want report-type of %q, got %q", want, got)
}
boundary := mtheaders["boundary"]
- expected = "Delivery Status Notification (Failure)"
- if msg.Header["Subject"][0] != expected {
- t.Errorf("Subject did not match %q, got %q", expected, mtheaders["Subject"])
+ if want, got := "Delivery Status Notification (Failure)", msg.Header["Subject"][0]; want != got {
+ t.Errorf("Want Subject field %q, got %q", want, got)
}
- if msg.Header["To"][0] != "<"+env.MailFrom.Address+">" {
- t.Errorf("To field does not match %q, got %q", env.MailFrom.Address, msg.Header["To"][0])
+ if want, got := "<"+env.MailFrom.Address+">", msg.Header["To"][0]; want != got {
+ t.Errorf("Want To field %q, got %q", want, got)
}
// Parse the multi-part messsage.
}
// First part is the human-readable error.
- expected = "text/plain; charset=UTF-8"
- if part.Header["Content-Type"][0] != expected {
- t.Errorf("Part 0 type expected %q, got %q", expected, part.Header["Content-Type"][0])
+ if want, got := "text/plain; charset=UTF-8", part.Header["Content-Type"][0]; want != got {
+ t.Errorf("Part 0 type want %q, got %q", want, got)
}
content, err := ioutil.ReadAll(part)
t.Errorf("Missing Delivery Failure")
}
- expected = fmt.Sprintf("%s:\n%s", errorStr1, errorStr2)
- if !strings.Contains(contentStr, expected) {
- t.Errorf("Missing error string %q", expected)
+ if want := fmt.Sprintf("%s:\n%s", errorStr1, errorStr2); !strings.Contains(contentStr, want) {
+ t.Errorf("Missing error string %q", want)
}
// Second part is the status information.
return
}
- expected = "message/delivery-status"
- if part.Header["Content-Type"][0] != expected {
- t.Errorf("Part 1 type expected %q, got %q", expected, part.Header["Content-Type"][0])
+ if want, got := "message/delivery-status", part.Header["Content-Type"][0]; want != got {
+ t.Errorf("Part 1 type want %q, got %q", want, got)
}
content, err = ioutil.ReadAll(part)
}
contentStr = string(content)
- expected = "Original-Envelope-ID: " + env.ID + "\n"
- if !strings.Contains(contentStr, expected) {
- t.Errorf("Missing %q in %q", expected, contentStr)
+ if want := "Original-Envelope-ID: " + env.ID + "\n"; !strings.Contains(contentStr, want) {
+ t.Errorf("Missing %q in %q", want, contentStr)
}
- expected = "Reporting-UA: " + env.EHLO + "\n"
- if !strings.Contains(contentStr, expected) {
- t.Errorf("Missing %q in %q", expected, contentStr)
+ if want := "Reporting-UA: " + env.EHLO + "\n"; !strings.Contains(contentStr, want) {
+ t.Errorf("Missing %q in %q", want, contentStr)
}
- expected = "Reporting-MTA: dns; localhost [127.0.0.1]\n"
- if !strings.Contains(contentStr, expected) {
- t.Errorf("Missing %q in %q", expected, contentStr)
+ if want := "Reporting-MTA: dns; localhost [127.0.0.1]\n"; !strings.Contains(contentStr, want) {
+ t.Errorf("Missing %q in %q", want, contentStr)
}
// Third part is the original message.
return
}
- expected = "message/rfc822"
- if part.Header["Content-Type"][0] != expected {
- t.Errorf("Part 2 type expected %q, got %q", expected, part.Header["Content-Type"][0])
+ if want, got := "message/rfc822", part.Header["Content-Type"][0]; want != got {
+ t.Errorf("Part 2 type want %q, got %q", want, got)
}
content, err = ioutil.ReadAll(part)