forked from smarty/cproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging_initializer_test.go
61 lines (46 loc) · 1.71 KB
/
logging_initializer_test.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
50
51
52
53
54
55
56
57
58
59
60
61
package cproxy
import (
"fmt"
"testing"
"github.com/smartystreets/assertions/should"
"github.com/smartystreets/gunit"
)
func TestLoggingInitializerFixture(t *testing.T) {
gunit.Run(new(LoggingInitializerFixture), t)
}
type LoggingInitializerFixture struct {
*gunit.Fixture
client *TestSocket
server *TestSocket
fakeInner *TestInitializer
initializer initializer
logs []string
}
func (this *LoggingInitializerFixture) Setup() {
this.client = NewTestSocket()
this.server = NewTestSocket()
this.client.address = "1.2.3.4"
this.client.port = 4321
this.server.address = "5.6.7.8"
this.server.port = 8765
this.fakeInner = NewTestInitializer(true)
this.initializer = newLoggingInitializer(&configuration{Logger: this, Initializer: this.fakeInner, LogConnections: true})
}
func (this *LoggingInitializerFixture) TestInnerInitializerCalled() {
result := this.initializer.Initialize(this.client, this.server)
this.So(result, should.BeTrue)
this.So(this.fakeInner.client, should.Equal, this.client)
this.So(this.fakeInner.server, should.Equal, this.server)
}
func (this *LoggingInitializerFixture) TestLoggingOnFailure() {
this.fakeInner.success = false
this.initializer.Initialize(this.client, this.server)
this.So(this.logs, should.Resemble, []string{"[INFO] Connection failed [1.2.3.4:4321] -> [5.6.7.8:8765]"})
}
func (this *LoggingInitializerFixture) TestLoggingOnSuccess() {
this.initializer.Initialize(this.client, this.server)
this.So(this.logs, should.Resemble, []string{"[INFO] Established connection [1.2.3.4:4321] -> [5.6.7.8:8765]"})
}
func (this *LoggingInitializerFixture) Printf(format string, args ...interface{}) {
this.logs = append(this.logs, fmt.Sprintf(format, args...))
}