From 32b16d1c43915f2d49cf79608558ef3efef26579 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Sun, 15 Mar 2015 18:52:38 -0400 Subject: [PATCH] Do away with the explict logger parameter. That was really overkill. All the expectNoLogs tests are just as easily serviced by looking at test output. There was only one test that actually asserted on log output and that was probably more trouble than was worth it. --- connection.go | 7 +-- connection_test.go | 53 +++++------------ log_util.go | 46 --------------- message_test.go | 16 ++---- reader.go | 19 +++---- reader_test.go | 132 ++++++++++++------------------------------- session.go | 13 ++--- session_test.go | 8 +-- subscription_test.go | 25 ++------ zephyr.go | 6 +- 10 files changed, 78 insertions(+), 247 deletions(-) delete mode 100644 log_util.go diff --git a/connection.go b/connection.go index 2f35c6a..24e3298 100644 --- a/connection.go +++ b/connection.go @@ -16,7 +16,6 @@ package zephyr import ( "errors" - "log" "net" "sync" "time" @@ -81,9 +80,8 @@ func NewConnection( conn net.PacketConn, server ServerConfig, cred *krb5.Credential, - logger *log.Logger, ) (*Connection, error) { - return NewConnectionFull(conn, server, cred, logger, SystemClock) + return NewConnectionFull(conn, server, cred, SystemClock) } // NewConnectionFull does the same as NewConnection but takes an @@ -92,7 +90,6 @@ func NewConnectionFull( conn net.PacketConn, server ServerConfig, cred *krb5.Credential, - logger *log.Logger, clock Clock, ) (*Connection, error) { c := new(Connection) @@ -104,7 +101,7 @@ func NewConnectionFull( if c.cred != nil { key = c.cred.KeyBlock } - c.allNotices = ReadNoticesFromServer(conn, key, logger) + c.allNotices = ReadNoticesFromServer(conn, key) c.notices = make(chan NoticeReaderResult) c.ackTable = make(map[UID]chan NoticeReaderResult) diff --git a/connection_test.go b/connection_test.go index 9929990..59035bc 100644 --- a/connection_test.go +++ b/connection_test.go @@ -51,14 +51,11 @@ func mockServer(t *testing.T, expectedAuthStatus AuthStatus, clock *zephyrtest.MockClock, numDrop int) { - l, lc := expectNoLogs(t) - defer lc.Close() - // Set some stuff up. ctx, keytab := makeServerContextAndKeyTab(t) defer ctx.Free() defer keytab.Close() - for r := range ReadRawNotices(conn, l) { + for r := range ReadRawNotices(conn) { authStatus, _, err := r.RawNotice.CheckAuthFromClient( ctx, krb5test.Service(), keytab) if err != nil { @@ -98,8 +95,6 @@ func mockServer(t *testing.T, // Tests that a Connection forwards received packets out and doesn't // send SERVACKs out. func TestConnectionReceive(t *testing.T) { - l, lc := expectNoLogs(t) - defer lc.Close() ctx, err := krb5.NewContext() if err != nil { t.Fatal(err) @@ -119,7 +114,7 @@ func TestConnectionReceive(t *testing.T) { close(readChan) mock := zephyrtest.NewMockPacketConn(clientAddr, readChan) clock := zephyrtest.NewMockClock() - conn, err := NewConnectionFull(mock, serverConfig, krb5test.Credential(), l, clock) + conn, err := NewConnectionFull(mock, serverConfig, krb5test.Credential(), clock) if err != nil { t.Fatal(err) } @@ -145,8 +140,6 @@ func TestConnectionReceive(t *testing.T) { } func TestConnectionSendNotice(t *testing.T) { - l, lc := expectNoLogs(t) - defer lc.Close() ctx, err := krb5.NewContext() if err != nil { t.Fatal(err) @@ -158,7 +151,7 @@ func TestConnectionSendNotice(t *testing.T) { client, server := mockNetwork1() defer server.Close() conn, err := NewConnectionFull(client, serverConfig, krb5test.Credential(), - l, clock) + clock) if err != nil { t.Fatal(err) } @@ -180,8 +173,6 @@ func TestConnectionSendNotice(t *testing.T) { } func TestConnectionSendNoticeRetransmit(t *testing.T) { - l, lc := expectNoLogs(t) - defer lc.Close() ctx, err := krb5.NewContext() if err != nil { t.Fatal(err) @@ -193,7 +184,7 @@ func TestConnectionSendNoticeRetransmit(t *testing.T) { client, server := mockNetwork1() defer server.Close() conn, err := NewConnectionFull(client, serverConfig, krb5test.Credential(), - l, clock) + clock) if err != nil { t.Fatal(err) } @@ -215,8 +206,6 @@ func TestConnectionSendNoticeRetransmit(t *testing.T) { } func TestConnectionSendNoticeTimeout(t *testing.T) { - l, lc := expectNoLogs(t) - defer lc.Close() ctx, err := krb5.NewContext() if err != nil { t.Fatal(err) @@ -228,7 +217,7 @@ func TestConnectionSendNoticeTimeout(t *testing.T) { client, server := mockNetwork1() defer server.Close() conn, err := NewConnectionFull(client, serverConfig, krb5test.Credential(), - l, clock) + clock) if err != nil { t.Fatal(err) } @@ -244,14 +233,12 @@ func TestConnectionSendNoticeTimeout(t *testing.T) { } func TestConnectionSendNoticeUnauth(t *testing.T) { - l, lc := expectNoLogs(t) - defer lc.Close() notice := sampleNotice() clock := zephyrtest.NewMockClock() client, server := mockNetwork1() defer server.Close() conn, err := NewConnectionFull(client, serverConfig, krb5test.Credential(), - l, clock) + clock) if err != nil { t.Fatal(err) } @@ -273,8 +260,6 @@ func TestConnectionSendNoticeUnauth(t *testing.T) { } func TestConnectionSendNoticeUnacked(t *testing.T) { - l, lc := expectNoLogs(t) - defer lc.Close() ctx, err := krb5.NewContext() if err != nil { t.Fatal(err) @@ -287,7 +272,7 @@ func TestConnectionSendNoticeUnacked(t *testing.T) { client, server := mockNetwork1() defer server.Close() conn, err := NewConnectionFull(client, serverConfig, krb5test.Credential(), - l, clock) + clock) if err != nil { t.Fatal(err) } @@ -306,8 +291,6 @@ func TestConnectionSendNoticeUnacked(t *testing.T) { } func TestConnectionSendNoticeRoundRobin(t *testing.T) { - l, lc := expectNoLogs(t) - defer lc.Close() ctx, err := krb5.NewContext() if err != nil { t.Fatal(err) @@ -320,7 +303,7 @@ func TestConnectionSendNoticeRoundRobin(t *testing.T) { defer server1.Close() defer server2.Close() conn, err := NewConnectionFull(client, serverConfigFull, krb5test.Credential(), - l, clock) + clock) if err != nil { t.Fatal(err) } @@ -363,8 +346,6 @@ func serverConfigNeedRefresh() ServerConfig { } func TestConnectionSendNoticeNeedRefresh(t *testing.T) { - l, lc := expectNoLogs(t) - defer lc.Close() ctx, err := krb5.NewContext() if err != nil { t.Fatal(err) @@ -377,7 +358,7 @@ func TestConnectionSendNoticeNeedRefresh(t *testing.T) { defer server1.Close() defer server2.Close() conn, err := NewConnectionFull(client, serverConfigNeedRefresh(), - krb5test.Credential(), l, clock) + krb5test.Credential(), clock) if err != nil { t.Fatal(err) } @@ -406,15 +387,13 @@ func TestConnectionSendNoticeNeedRefresh(t *testing.T) { } func TestConnectionSendNoticeWriteFailure(t *testing.T) { - l, lc := expectNoLogs(t) - defer lc.Close() notice := sampleNotice() clock := zephyrtest.NewMockClock() readChan := make(chan zephyrtest.PacketRead) close(readChan) mock := zephyrtest.NewMockPacketConn(clientAddr, readChan) conn, err := NewConnectionFull(mock, serverConfig, krb5test.Credential(), - l, clock) + clock) if err != nil { t.Fatal(err) } @@ -435,8 +414,6 @@ func TestConnectionSendNoticeWriteFailure(t *testing.T) { } func TestConnectionSendGiantNotices(t *testing.T) { - l, lc := expectNoLogs(t) - defer lc.Close() notice := sampleNotice() notice.RawBody = make([]byte, 99999) @@ -444,7 +421,7 @@ func TestConnectionSendGiantNotices(t *testing.T) { client, server := mockNetwork1() defer server.Close() conn, err := NewConnectionFull(client, serverConfig, krb5test.Credential(), - l, clock) + clock) if err != nil { t.Fatal(err) } @@ -464,14 +441,12 @@ func (sc signalingConfig) ResolveServer() ([]*net.UDPAddr, error) { } func TestConnectionPeriodicRefresh(t *testing.T) { - l, lc := expectNoLogs(t) - defer lc.Close() config := signalingConfig(make(chan int, 2)) clock := zephyrtest.NewMockClock() client, server := mockNetwork1() defer server.Close() - conn, err := NewConnectionFull(client, config, krb5test.Credential(), l, clock) + conn, err := NewConnectionFull(client, config, krb5test.Credential(), clock) if err != nil { t.Fatal(err) } @@ -509,8 +484,6 @@ func (f *failingConfig) ResolveServer() ([]*net.UDPAddr, error) { } func TestConnectionFailingConfigMidSend(t *testing.T) { - l, lc := expectNoLogs(t) - defer lc.Close() ctx, err := krb5.NewContext() if err != nil { t.Fatal(err) @@ -524,7 +497,7 @@ func TestConnectionFailingConfigMidSend(t *testing.T) { defer server2.Close() conn, err := NewConnectionFull(client, newFailingConfig(1, serverConfigNeedRefresh()), - krb5test.Credential(), l, clock) + krb5test.Credential(), clock) if err != nil { t.Fatal(err) } diff --git a/log_util.go b/log_util.go deleted file mode 100644 index a7bf68f..0000000 --- a/log_util.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2014 The zephyr-go authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package zephyr - -import ( - "log" -) - -// This is silly. Why doesn't the log package expose the standard -// logger? - -func logPrint(l *log.Logger, v ...interface{}) { - if l != nil { - l.Print(v...) - } else { - log.Print(v...) - } -} - -func logPrintf(l *log.Logger, format string, v ...interface{}) { - if l != nil { - l.Printf(format, v...) - } else { - log.Printf(format, v...) - } -} - -func logPrintln(l *log.Logger, v ...interface{}) { - if l != nil { - l.Println(v...) - } else { - log.Println(v...) - } -} diff --git a/message_test.go b/message_test.go index 755b764..83dce02 100644 --- a/message_test.go +++ b/message_test.go @@ -37,8 +37,6 @@ func testSendMessage(t *testing.T, l int, auth AuthStatus) { msg := &Message{sampleNotice().Header, body} - logger, lc := expectNoLogs(t) - defer lc.Close() ctx, err := krb5.NewContext() if err != nil { t.Error(err) @@ -49,7 +47,7 @@ func testSendMessage(t *testing.T, l int, auth AuthStatus) { clock := zephyrtest.NewMockClock() client, server := mockNetwork1() conn, err := NewConnectionFull(client, serverConfig, - krb5test.Credential(), logger, clock) + krb5test.Credential(), clock) if err != nil { t.Error(err) return @@ -117,13 +115,11 @@ func TestSendMessage(t *testing.T) { } func TestSendMessageLongHeader(t *testing.T) { - l, lc := expectNoLogs(t) - defer lc.Close() clock := zephyrtest.NewMockClock() client, server := mockNetwork1() defer server.Close() conn, err := NewConnectionFull(client, serverConfig, - krb5test.Credential(), l, clock) + krb5test.Credential(), clock) if err != nil { t.Fatal(err) } @@ -143,13 +139,11 @@ func TestSendMessageLongHeader(t *testing.T) { } func TestSendMessageNack(t *testing.T) { - l, lc := expectNoLogs(t) - defer lc.Close() clock := zephyrtest.NewMockClock() client, server := mockNetwork1() defer server.Close() conn, err := NewConnectionFull(client, serverConfig, - krb5test.Credential(), l, clock) + krb5test.Credential(), clock) if err != nil { t.Fatal(err) } @@ -175,14 +169,12 @@ func TestSendMessageNack(t *testing.T) { } func TestSendMessageSendError(t *testing.T) { - l, lc := expectNoLogs(t) - defer lc.Close() clock := zephyrtest.NewMockClock() readChan := make(chan zephyrtest.PacketRead) close(readChan) mock := zephyrtest.NewMockPacketConn(clientAddr, readChan) conn, err := NewConnectionFull(mock, serverConfig, - krb5test.Credential(), l, clock) + krb5test.Credential(), clock) if err != nil { t.Fatal(err) } diff --git a/reader.go b/reader.go index 700f2e1..5710887 100644 --- a/reader.go +++ b/reader.go @@ -36,15 +36,14 @@ type RawReaderResult struct { // ReadRawNotices decodes packets from a PacketConn into RawNotices // and returns a stream of them. Non-fatal errors are returned through // the stream. On a fatal error or EOF, the channel is closed. -func ReadRawNotices(conn net.PacketConn, logger *log.Logger) <-chan RawReaderResult { +func ReadRawNotices(conn net.PacketConn) <-chan RawReaderResult { sink := make(chan RawReaderResult) - go readRawNoticeLoop(conn, logger, sink) + go readRawNoticeLoop(conn, sink) return sink } func readRawNoticeLoop( conn net.PacketConn, - logger *log.Logger, sink chan<- RawReaderResult, ) { defer close(sink) @@ -55,7 +54,7 @@ func readRawNoticeLoop( if err != nil { // Send the error out to the consumer. if err != io.EOF { - logPrintf(logger, "Error reading packet: %v\n", err) + log.Printf("Error reading packet: %v\n", err) } if ne, ok := err.(net.Error); ok && ne.Temporary() { // Delay logic from net/http.Serve. @@ -77,7 +76,7 @@ func readRawNoticeLoop( // Copy the packet so we can reuse the buffer. raw, err := DecodePacket(copyByteSlice(buf[0:n])) if err != nil { - logPrintf(logger, "Error decoding notice: %v\n", err) + log.Printf("Error decoding notice: %v\n", err) continue } sink <- RawReaderResult{raw, addr} @@ -100,31 +99,29 @@ type NoticeReaderResult struct { func ReadNoticesFromServer( conn net.PacketConn, key *krb5.KeyBlock, - logger *log.Logger, ) <-chan NoticeReaderResult { // TODO(davidben): Should this channel be buffered a little? sink := make(chan NoticeReaderResult) - go readNoticeLoop(ReadRawNotices(conn, logger), key, logger, sink) + go readNoticeLoop(ReadRawNotices(conn), key, sink) return sink } func readNoticeLoop( rawReader <-chan RawReaderResult, key *krb5.KeyBlock, - logger *log.Logger, sink chan<- NoticeReaderResult, ) { defer close(sink) ctx, err := krb5.NewContext() if err != nil { - logPrintf(logger, "Error creating krb5 context: %v", err) + log.Printf("Error creating krb5 context: %v", err) return } defer ctx.Free() for r := range rawReader { notice, err := DecodeRawNotice(r.RawNotice) if err != nil { - logPrintf(logger, "Error parsing notice: %v", err) + log.Printf("Error parsing notice: %v", err) continue } @@ -135,7 +132,7 @@ func readNoticeLoop( } else if key != nil { authStatus, err = r.RawNotice.CheckAuthFromServer(ctx, key) if err != nil { - logPrintf(logger, "Error authenticating notice: %v", err) + log.Printf("Error authenticating notice: %v", err) authStatus = AuthFailed } } diff --git a/reader_test.go b/reader_test.go index 89152e6..b82a782 100644 --- a/reader_test.go +++ b/reader_test.go @@ -15,11 +15,11 @@ package zephyr import ( - "bufio" "errors" - "io" + "io/ioutil" "log" "net" + "os" "reflect" "testing" @@ -27,55 +27,20 @@ import ( "github.com/zephyr-im/zephyr-go/zephyrtest" ) -func newTestLogger() (*log.Logger, io.Closer, <-chan string) { - pr, pw := io.Pipe() - l := log.New(pw, "", 0) - c := make(chan string) - go func() { - s := bufio.NewScanner(pr) - for s.Scan() { - c <- s.Text() - } - // Meh. - if err := s.Err(); err != nil { - c <- "Error scanning: " + err.Error() - } - close(c) - }() - return l, pw, c -} - -func expectNoLogs(t *testing.T) (*log.Logger, io.Closer) { - l, closer, c := newTestLogger() - go func() { - for line := range c { - t.Error(line) - } - }() - return l, closer -} - func TestReadNoticesFromServer(t *testing.T) { + // This test is noisy. + log.SetOutput(ioutil.Discard) + defer log.SetOutput(os.Stderr) + addr1 := &net.UDPAddr{IP: net.IPv4(1, 1, 1, 1), Port: 1111} addr2 := &net.UDPAddr{IP: net.IPv4(2, 2, 2, 2), Port: 2222} clientAddr := &net.UDPAddr{IP: net.IPv4(3, 3, 3, 3), Port: 3333} fatalErr := errors.New("polarity insufficiently reversed") - type resultOrErr struct { - r *NoticeReaderResult - line string - } - result := func(n *Notice, as AuthStatus, addr net.Addr) resultOrErr { - return resultOrErr{r: &NoticeReaderResult{n, as, addr}} - } - err := func(line string) resultOrErr { - return resultOrErr{line: line} - } - type test struct { keyblock *krb5.KeyBlock reads []zephyrtest.PacketRead - expected []resultOrErr + expected []*NoticeReaderResult } tests := []test{ // Basic case @@ -83,8 +48,8 @@ func TestReadNoticesFromServer(t *testing.T) { sampleKeyBlock(), []zephyrtest.PacketRead{ {samplePacket(), addr1, nil}, - }, []resultOrErr{ - result(sampleNotice(), AuthYes, addr1), + }, []*NoticeReaderResult{ + {sampleNotice(), AuthYes, addr1}, }, }, // Various non-fatal errors. @@ -102,25 +67,18 @@ func TestReadNoticesFromServer(t *testing.T) { {[]byte("bogus"), addr2, nil}, {samplePacket(), addr1, nil}, }, - []resultOrErr{ - err("Error reading packet: Temporary error"), - result(sampleNotice(), AuthYes, addr1), - err("Error reading packet: Temporary error"), - err("Error reading packet: Temporary error"), + []*NoticeReaderResult{ + // samplePacket + {sampleNotice(), AuthYes, addr1}, // samplePacket - result(sampleNotice(), AuthYes, addr2), + {sampleNotice(), AuthYes, addr2}, // sampleFailPacket - result(sampleNotice(), AuthFailed, addr1), + {sampleNotice(), AuthFailed, addr1}, // sampleMalformedChecksumPacket - err("Error authenticating notice: invalid zcode"), - result(sampleNotice(), AuthFailed, addr2), - // sampleMalformedPortPacket - err("Error parsing notice: bad length for " + - "uint16 zephyrascii"), - // bogus - err("Error decoding notice: bad packet format"), + {sampleNotice(), AuthFailed, addr2}, + // sampleMalformedPortPacket and bogus are dropped. // samplePacket - result(sampleNotice(), AuthYes, addr1), + {sampleNotice(), AuthYes, addr1}, }, }, // Stop after fatal error. @@ -130,18 +88,15 @@ func TestReadNoticesFromServer(t *testing.T) { {nil, nil, fatalErr}, {samplePacket(), addr1, nil}, }, - []resultOrErr{ - err("Error reading packet: polarity " + - "insufficiently reversed"), - }, + []*NoticeReaderResult{}, }, // nil key. { nil, []zephyrtest.PacketRead{ {samplePacket(), addr1, nil}, - }, []resultOrErr{ - result(sampleNotice(), AuthFailed, addr1), + }, []*NoticeReaderResult{ + {sampleNotice(), AuthFailed, addr1}, }, }, } @@ -156,42 +111,27 @@ func TestReadNoticesFromServer(t *testing.T) { close(readChan) }() mock := zephyrtest.NewMockPacketConn(clientAddr, readChan) - l, closer, lines := newTestLogger() - out := ReadNoticesFromServer(mock, test.keyblock, l) + out := ReadNoticesFromServer(mock, test.keyblock) for ei, expect := range test.expected { - if expect.r != nil { - if r, ok := <-out; !ok { - t.Errorf("%d.%d. Expected notice: %v", - ti, ei, expect.r) - } else { - expectNoticesEqual(t, r.Notice, expect.r.Notice) - if r.AuthStatus != expect.r.AuthStatus { - t.Errorf("%d.%d. AuthStatus = %v; want %v", - ti, ei, - r.AuthStatus, - expect.r.AuthStatus) - } - if !reflect.DeepEqual(r.Addr, expect.r.Addr) { - t.Errorf("%d.%d. Addr = %v; want %v", - ti, ei, - r.Addr, - expect.r.Addr) - } - } + if r, ok := <-out; !ok { + t.Errorf("%d.%d. Expected notice: %v", + ti, ei, expect) } else { - if line, ok := <-lines; !ok { - t.Errorf("%d.%d. Expected error: %v", - ti, ei, expect.line) - } else if line != expect.line { - t.Errorf("%d.%d. line = %v; wanted %v", - ti, ei, line, expect.line) + expectNoticesEqual(t, r.Notice, expect.Notice) + if r.AuthStatus != expect.AuthStatus { + t.Errorf("%d.%d. AuthStatus = %v; want %v", + ti, ei, + r.AuthStatus, + expect.AuthStatus) + } + if !reflect.DeepEqual(r.Addr, expect.Addr) { + t.Errorf("%d.%d. Addr = %v; want %v", + ti, ei, + r.Addr, + expect.Addr) } } } - closer.Close() - for line := range lines { - t.Errorf("%d. unexpected line: %v", ti, line) - } for r := range out { t.Errorf("%d. unexpected notice: %v", ti, r) } diff --git a/session.go b/session.go index 78c76c1..819155a 100644 --- a/session.go +++ b/session.go @@ -38,7 +38,6 @@ type MessageReaderResult struct { // notices by UID. This API should be used by most zephyr clients. type Session struct { conn *Connection - logger *log.Logger clock Clock messages chan MessageReaderResult } @@ -49,9 +48,8 @@ func NewSession( conn net.PacketConn, server ServerConfig, cred *krb5.Credential, - logger *log.Logger, ) (*Session, error) { - return NewSessionFull(conn, server, cred, logger, SystemClock) + return NewSessionFull(conn, server, cred, SystemClock) } // NewSessionFull creates a new Session attached to a given connection @@ -61,15 +59,14 @@ func NewSessionFull( conn net.PacketConn, server ServerConfig, cred *krb5.Credential, - logger *log.Logger, clock Clock, ) (*Session, error) { - zconn, err := NewConnectionFull(conn, server, cred, logger, clock) + zconn, err := NewConnectionFull(conn, server, cred, clock) if err != nil { return nil, err } - s := &Session{zconn, logger, clock, make(chan MessageReaderResult)} + s := &Session{zconn, clock, make(chan MessageReaderResult)} go s.noticeLoop() return s, nil } @@ -99,13 +96,13 @@ func (s *Session) noticeLoop() { var err error msg, err = NewReassemblerFromMultipartField(r.Notice) if err != nil { - logPrintf(s.logger, "Error parsing multipart: %v", err) + log.Printf("Error parsing multipart: %v", err) continue } reassemble.Put(r.Notice.MultiUID, msg) } if err := msg.AddNotice(r.Notice, r.AuthStatus); err != nil { - logPrintf(s.logger, "Error reassembling notice: %v", err) + log.Printf("Error reassembling notice: %v", err) continue } if msg.Done() { diff --git a/session_test.go b/session_test.go index 2a988c2..9543703 100644 --- a/session_test.go +++ b/session_test.go @@ -38,13 +38,11 @@ func mockSendingServer( notices []noticeWithAuth, ) { // Set some stuff up. - l, lc := expectNoLogs(t) - defer lc.Close() ctx, keytab := makeServerContextAndKeyTab(t) defer ctx.Free() defer keytab.Close() - rawNotices := ReadRawNotices(conn, l) + rawNotices := ReadRawNotices(conn) for _, n := range notices { // Assemble the notice to send out. pkt, err := n.notice.EncodePacketForClient(ctx, n.authStatus, key) @@ -75,8 +73,6 @@ func mockSendingServer( } func TestSession(t *testing.T) { - l, lc := expectNoLogs(t) - defer lc.Close() ctx, err := krb5.NewContext() if err != nil { t.Fatal(err) @@ -87,7 +83,7 @@ func TestSession(t *testing.T) { clock := zephyrtest.NewMockClock() client, server1, server2 := mockNetwork2() session, err := NewSessionFull(client, serverConfigFull, krb5test.Credential(), - l, clock) + clock) if err != nil { t.Fatal(err) } diff --git a/subscription_test.go b/subscription_test.go index e00b101..a028b80 100644 --- a/subscription_test.go +++ b/subscription_test.go @@ -28,12 +28,10 @@ import ( ) func ackAndDumpNotices(t *testing.T, conn net.PacketConn, auth AuthStatus, sink chan<- *Notice) { - l, lc := expectNoLogs(t) - defer lc.Close() ctx, keytab := makeServerContextAndKeyTab(t) defer ctx.Free() defer keytab.Close() - for r := range ReadRawNotices(conn, l) { + for r := range ReadRawNotices(conn) { authStatus, _, err := r.RawNotice.CheckAuthFromClient( ctx, krb5test.Service(), keytab) if err != nil { @@ -58,9 +56,7 @@ func ackAndDumpNotices(t *testing.T, conn net.PacketConn, auth AuthStatus, sink } func nackNotices(t *testing.T, conn net.PacketConn) { - l, lc := expectNoLogs(t) - defer lc.Close() - for r := range ReadRawNotices(conn, l) { + for r := range ReadRawNotices(conn) { notice, err := DecodeRawNotice(r.RawNotice) if err != nil { t.Fatalf("DecodeRawNotice failed: %v", err) @@ -134,9 +130,6 @@ func TestSendSubscribe(t *testing.T) { tests = append(tests, long) for i, subs := range tests { - l, lc := expectNoLogs(t) - defer lc.Close() - ctx, err := krb5.NewContext() if err != nil { t.Fatal(err) @@ -146,7 +139,7 @@ func TestSendSubscribe(t *testing.T) { clock := zephyrtest.NewMockClock() client, server := mockNetwork1() conn, err := NewConnectionFull(client, serverConfig, - krb5test.Credential(), l, clock) + krb5test.Credential(), clock) if err != nil { t.Fatal(err) } @@ -189,8 +182,6 @@ func TestSendSubscribe(t *testing.T) { } func TestSendSubscribeTooLong(t *testing.T) { - l, lc := expectNoLogs(t) - defer lc.Close() ctx, err := krb5.NewContext() if err != nil { t.Fatal(err) @@ -201,7 +192,7 @@ func TestSendSubscribeTooLong(t *testing.T) { client, server := mockNetwork1() defer server.Close() conn, err := NewConnectionFull(client, serverConfig, - krb5test.Credential(), l, clock) + krb5test.Credential(), clock) if err != nil { t.Fatal(err) } @@ -224,8 +215,6 @@ func TestSendSubscribeNack(t *testing.T) { {"davidben@ATHENA.MIT.EDU", "message", "personal"}, } - l, lc := expectNoLogs(t) - defer lc.Close() ctx, err := krb5.NewContext() if err != nil { t.Fatal(err) @@ -236,7 +225,7 @@ func TestSendSubscribeNack(t *testing.T) { client, server := mockNetwork1() defer server.Close() conn, err := NewConnectionFull(client, serverConfig, - krb5test.Credential(), l, clock) + krb5test.Credential(), clock) if err != nil { t.Fatal(err) } @@ -263,8 +252,6 @@ func TestSendSubscribeSendError(t *testing.T) { {"davidben@ATHENA.MIT.EDU", "message", "personal"}, } - l, lc := expectNoLogs(t) - defer lc.Close() ctx, err := krb5.NewContext() if err != nil { t.Fatal(err) @@ -276,7 +263,7 @@ func TestSendSubscribeSendError(t *testing.T) { close(readChan) mock := zephyrtest.NewMockPacketConn(clientAddr, readChan) conn, err := NewConnectionFull(mock, serverConfig, - krb5test.Credential(), l, clock) + krb5test.Credential(), clock) if err != nil { t.Fatal(err) } diff --git a/zephyr.go b/zephyr.go index 49db643..060f3be 100644 --- a/zephyr.go +++ b/zephyr.go @@ -27,7 +27,6 @@ package zephyr import ( - "log" "net" "github.com/zephyr-im/hesiod-go" @@ -60,7 +59,7 @@ func DialSystemDefault() (*Session, error) { if err != nil { return nil, err } - return Dial(hesiod.NewHesiod(), cred, nil) + return Dial(hesiod.NewHesiod(), cred) } // Dial creates a new Session using the given Hesiod object and @@ -68,7 +67,6 @@ func DialSystemDefault() (*Session, error) { func Dial( hesiod *hesiod.Hesiod, cred *krb5.Credential, - logger *log.Logger, ) (*Session, error) { // Create a server config from Hesiod. server, err := NewServerFromHesiod(hesiod) @@ -82,5 +80,5 @@ func Dial( return nil, err } - return NewSession(udp, server, cred, logger) + return NewSession(udp, server, cred) }