storj/pkg/telemetry/server_test.go
Yehor Butko 7ea075ce9e Unit Tests for logging.go added (#148)
* Unit Tests for logging.go added.

* Unit Tests for logging.go added part 2

* Unit tests added for Utils package
2018-07-19 15:41:29 -04:00

45 lines
820 B
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package telemetry
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestListen_NilOnBadAddress(t *testing.T) {
server, errListen := Listen("11")
defer func() {
if server != nil {
server.Close()
}
}()
assert.Nil(t, server)
assert.Error(t, errListen)
}
func TestServe_ReturnErrorOnConnFail(t *testing.T) {
server, _ := Listen("127.0.0.1:0")
defer func() {
if server != nil && server.conn != nil {
server.Close()
}
}()
server.conn.Close()
server.conn = nil
errServe := server.Serve(nil, nil)
assert.EqualError(t, errServe, "telemetry error: invalid conn: <nil>")
}
func TestListenAndServe_ReturnErrorOnListenFails(t *testing.T) {
err := ListenAndServe(nil, "1", nil)
assert.Error(t, err)
}