mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-26 16:09:45 -05:00
37aff14cab
Signed-off-by: Daniel Weiße <dw@edgeless.systems>
38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
package pubapi
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"go.uber.org/goleak"
|
|
grpcpeer "google.golang.org/grpc/peer"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
goleak.VerifyTestMain(m,
|
|
// https://github.com/census-instrumentation/opencensus-go/issues/1262
|
|
goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"),
|
|
// https://github.com/kubernetes/klog/issues/282, https://github.com/kubernetes/klog/issues/188
|
|
goleak.IgnoreTopFunction("k8s.io/klog/v2.(*loggingT).flushDaemon"),
|
|
)
|
|
}
|
|
|
|
func TestGetRecoveryPeerFromContext(t *testing.T) {
|
|
assert := assert.New(t)
|
|
testIP := "192.0.2.1"
|
|
testPort := 1234
|
|
expectedPeer := net.JoinHostPort(testIP, "9000")
|
|
|
|
addr := &net.TCPAddr{IP: net.ParseIP(testIP), Port: testPort}
|
|
ctx := grpcpeer.NewContext(context.Background(), &grpcpeer.Peer{Addr: addr})
|
|
|
|
peer, err := GetRecoveryPeerFromContext(ctx)
|
|
assert.NoError(err)
|
|
assert.Equal(expectedPeer, peer)
|
|
|
|
_, err = GetRecoveryPeerFromContext(context.Background())
|
|
assert.Error(err)
|
|
}
|