1
0
mirror of https://github.com/golang/go synced 2024-11-23 21:10:05 -07:00

net/smtp: fix dropped test error

Pick up a dropped error in TestSendMailWithAuth() and simplify goroutine
to use an error channel instead of a sync.WaitGroup and an empty struct
doneCh.

Change-Id: Ie70d0f7c4c85835eb682e81d086ce4d9900269e6
Reviewed-on: https://go-review.googlesource.com/c/go/+/205247
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Lars Lehtonen 2019-11-04 18:13:06 -08:00 committed by Brad Fitzpatrick
parent 9a0a824456
commit 979d65dbc7

View File

@ -9,13 +9,13 @@ import (
"bytes"
"crypto/tls"
"crypto/x509"
"fmt"
"internal/testenv"
"io"
"net"
"net/textproto"
"runtime"
"strings"
"sync"
"testing"
"time"
)
@ -642,13 +642,13 @@ func TestSendMailWithAuth(t *testing.T) {
t.Fatalf("Unable to create listener: %v", err)
}
defer l.Close()
wg := sync.WaitGroup{}
var done = make(chan struct{})
errCh := make(chan error)
go func() {
defer wg.Done()
defer close(errCh)
conn, err := l.Accept()
if err != nil {
t.Errorf("Accept error: %v", err)
errCh <- fmt.Errorf("Accept: %v", err)
return
}
defer conn.Close()
@ -659,10 +659,11 @@ func TestSendMailWithAuth(t *testing.T) {
if msg == "EHLO localhost" {
tc.PrintfLine("250 mx.google.com at your service")
}
// for this test case, there should have no more traffic
<-done
if err != nil {
errCh <- fmt.Errorf("PrintfLine: %v", err)
return
}
}()
wg.Add(1)
err = SendMail(l.Addr().String(), PlainAuth("", "user", "pass", "smtp.google.com"), "test@example.com", []string{"other@example.com"}, []byte(strings.Replace(`From: test@example.com
To: other@example.com
@ -676,8 +677,10 @@ SendMail is working for me.
if err.Error() != "smtp: server doesn't support AUTH" {
t.Errorf("Expected: smtp: server doesn't support AUTH, got: %s", err)
}
close(done)
wg.Wait()
err = <-errCh
if err != nil {
t.Fatalf("server error: %v", err)
}
}
func TestAuthFailed(t *testing.T) {