-
Notifications
You must be signed in to change notification settings - Fork 4
/
server_mock.go
49 lines (43 loc) · 1.14 KB
/
server_mock.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2013 The Go-IMAP Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the go-imap.LICENSE file.
package imap
import (
"crypto/tls"
"net"
)
// MockServer is an internal type exposed for use by the mock package.
type MockServer interface {
Compressed() bool
Encrypted() bool
Closed() bool
ReadLine() (line []byte, err error)
WriteLine(line []byte) error
Read(p []byte) (n int, err error)
Write(p []byte) (n int, err error)
Flush() error
EnableDeflate(level int) error
EnableTLS(config *tls.Config) error
Close(flush bool) error
}
// NewMockServer is an internal function exposed for use by the mock package.
func NewMockServer(conn net.Conn) MockServer {
gotest = true
return mockServer{newTransport(conn, nil)}
}
type mockServer struct{ *transport }
func (t mockServer) EnableTLS(config *tls.Config) (err error) {
if t.Encrypted() {
return ErrEncryptionActive
}
conn := tls.Server(t.conn, config)
if err = conn.Handshake(); err == nil {
t.conn = conn
if t.Compressed() {
t.cmpLink.Attach(conn, conn)
} else {
t.bufLink.Attach(conn, conn)
}
}
return
}