Skip to content

Commit

Permalink
Fix unit tests and default NormalLogger
Browse files Browse the repository at this point in the history
  • Loading branch information
winsock committed Mar 31, 2021
1 parent bed6736 commit 2b5623c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
7 changes: 7 additions & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ type Options struct {
ExitTimeout time.Duration // How long should we wait for FreeSWITCH to respond to our "exit" command. 5 seconds is a sane default.
}

// DefaultOptions - The default options used for creating the connection
var DefaultOptions = Options{
Context: context.Background(),
Logger: NormalLogger{},
ExitTimeout: 5 * time.Second,
}

const EndOfMessage = "\r\n\r\n"

func newConnection(c net.Conn, outbound bool, opts Options) *Conn {
Expand Down
2 changes: 1 addition & 1 deletion connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

func TestConn_SendCommand(t *testing.T) {
server, client := net.Pipe()
connection := newConnection(client, false)
connection := newConnection(client, false, DefaultOptions)
defer connection.Close()
defer server.Close()
defer client.Close()
Expand Down
2 changes: 1 addition & 1 deletion event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const TestEventToSend = "Content-Length: 483\r\nContent-Type: text/event-plain\r

func TestEvent_readPlainEvent(t *testing.T) {
server, client := net.Pipe()
connection := newConnection(client, false)
connection := newConnection(client, false, DefaultOptions)
defer connection.Close()
defer server.Close()
defer client.Close()
Expand Down
6 changes: 1 addition & 5 deletions inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ type InboundOptions struct {

// DefaultOutboundOptions - The default options used for creating the inbound connection
var DefaultInboundOptions = InboundOptions{
Options: Options{
Context: context.Background(),
Logger: NormalLogger{},
ExitTimeout: 5 * time.Second,
},
Options: DefaultOptions,
Network: "tcp",
Password: "ClueCon",
AuthTimeout: 5 * time.Second,
Expand Down
8 changes: 4 additions & 4 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ type NormalLogger struct{}

func (l NormalLogger) Debug(format string, args ...interface{}) {
log.Print("DEBUG: ")
log.Printf(format, args)
log.Printf(format, args...)
}
func (l NormalLogger) Info(format string, args ...interface{}) {
log.Print("INFO: ")
log.Printf(format, args)
log.Printf(format, args...)
}
func (l NormalLogger) Warn(format string, args ...interface{}) {
log.Print("WARN: ")
log.Printf(format, args)
log.Printf(format, args...)
}
func (l NormalLogger) Error(format string, args ...interface{}) {
log.Print("ERROR: ")
log.Printf(format, args)
log.Printf(format, args...)
}

func (l NilLogger) Debug(string, ...interface{}) {}
Expand Down
6 changes: 1 addition & 5 deletions outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ type OutboundOptions struct {

// DefaultOutboundOptions - The default options used for creating the outbound connection
var DefaultOutboundOptions = OutboundOptions{
Options: Options{
Context: context.Background(),
Logger: NormalLogger{},
ExitTimeout: 5 * time.Second,
},
Options: DefaultOptions,
Network: "tcp",
ConnectTimeout: 5 * time.Second,
ConnectionDelay: 25 * time.Millisecond,
Expand Down

0 comments on commit 2b5623c

Please sign in to comment.