0f5a2f4ef5
* enable more linters * Run gofmt -s * run goimports * run unconvert * fix naked return * fix misspellings * fix ineffectual assigments * fix missing declaration * don't use deprecated grpc.Errof * check errors in tests * run gofmt -w -r "assert.Nil(err) -> assert.NoError(err)" * fix directory permissions * don't use nil Context * simplify boolean expressions * use bytes.Equal instead of bytes.Compare * merge variable declarations, remove redundant returns * fix some golint errors * run goimports * handle more errors * delete empty TestMain * delete empty TestMain * ignore examples for now * fix lint errors * remove unused values * more fixes * run gofmt -w -s . * add more comments * fix naming * more lint fixes * try switching travis to go1.11 * fix unnecessary conversions * fix deprecated methods * use go1.10 and disable gofmt/goimports for now * switch to 1.10 * don't re-enable gofmt and goimports * switch covermode to atomic because of -race * gofmt
46 lines
865 B
Go
46 lines
865 B
Go
// Copyright (C) 2018 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package telemetry
|
|
|
|
import (
|
|
"context"
|
|
"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(context.Background(), nil)
|
|
|
|
assert.EqualError(t, errServe, "telemetry error: invalid conn: <nil>")
|
|
}
|
|
|
|
func TestListenAndServe_ReturnErrorOnListenFails(t *testing.T) {
|
|
err := ListenAndServe(context.Background(), "1", nil)
|
|
|
|
assert.Error(t, err)
|
|
}
|