2018-07-19 20:41:29 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package telemetry
|
|
|
|
|
|
|
|
import (
|
2018-08-27 18:28:16 +01:00
|
|
|
"context"
|
2018-07-19 20:41:29 +01:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestListen_NilOnBadAddress(t *testing.T) {
|
|
|
|
server, errListen := Listen("11")
|
|
|
|
defer func() {
|
|
|
|
if server != nil {
|
2018-09-11 14:13:25 +01:00
|
|
|
assert.NoError(t, server.Close())
|
2018-07-19 20:41:29 +01:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
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 {
|
2018-09-11 14:13:25 +01:00
|
|
|
assert.NoError(t, server.Close())
|
2018-07-19 20:41:29 +01:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2018-09-11 14:13:25 +01:00
|
|
|
assert.NoError(t, server.conn.Close())
|
2018-07-19 20:41:29 +01:00
|
|
|
server.conn = nil
|
|
|
|
|
2018-08-27 18:28:16 +01:00
|
|
|
errServe := server.Serve(context.Background(), nil)
|
2018-07-19 20:41:29 +01:00
|
|
|
|
|
|
|
assert.EqualError(t, errServe, "telemetry error: invalid conn: <nil>")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestListenAndServe_ReturnErrorOnListenFails(t *testing.T) {
|
2018-08-27 18:28:16 +01:00
|
|
|
err := ListenAndServe(context.Background(), "1", nil)
|
2018-07-19 20:41:29 +01:00
|
|
|
assert.Error(t, err)
|
|
|
|
}
|