xds: Pass in logger

small cleanup in tests
This commit is contained in:
Daniel Nephin 2020-12-23 12:50:28 -05:00
parent 4f15f83dc6
commit 375aed5ed6
7 changed files with 26 additions and 40 deletions

View File

@ -650,7 +650,7 @@ func (a *Agent) listenAndServeGRPC() error {
} }
xdsServer := &xds.Server{ xdsServer := &xds.Server{
Logger: a.logger, Logger: a.logger.Named(logging.Envoy),
CfgMgr: a.proxyConfig, CfgMgr: a.proxyConfig,
ResolveToken: a.resolveToken, ResolveToken: a.resolveToken,
CheckFetcher: a, CheckFetcher: a,

View File

@ -10,12 +10,13 @@ import (
envoy "github.com/envoyproxy/go-control-plane/envoy/api/v2" envoy "github.com/envoyproxy/go-control-plane/envoy/api/v2"
"github.com/golang/protobuf/ptypes/wrappers" "github.com/golang/protobuf/ptypes/wrappers"
testinf "github.com/mitchellh/go-testing-interface"
"github.com/stretchr/testify/require"
"github.com/hashicorp/consul/agent/proxycfg" "github.com/hashicorp/consul/agent/proxycfg"
"github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/agent/xds/proxysupport" "github.com/hashicorp/consul/agent/xds/proxysupport"
"github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/sdk/testutil"
testinf "github.com/mitchellh/go-testing-interface"
"github.com/stretchr/testify/require"
) )
func TestClustersFromSnapshot(t *testing.T) { func TestClustersFromSnapshot(t *testing.T) {
@ -665,10 +666,7 @@ func TestClustersFromSnapshot(t *testing.T) {
} }
// Need server just for logger dependency // Need server just for logger dependency
logger := testutil.Logger(t) s := Server{Logger: testutil.Logger(t)}
s := Server{
Logger: logger,
}
cInfo := connectionInfo{ cInfo := connectionInfo{
Token: "my-token", Token: "my-token",

View File

@ -12,11 +12,12 @@ import (
envoy "github.com/envoyproxy/go-control-plane/envoy/api/v2" envoy "github.com/envoyproxy/go-control-plane/envoy/api/v2"
envoycore "github.com/envoyproxy/go-control-plane/envoy/api/v2/core" envoycore "github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
envoyendpoint "github.com/envoyproxy/go-control-plane/envoy/api/v2/endpoint" envoyendpoint "github.com/envoyproxy/go-control-plane/envoy/api/v2/endpoint"
testinf "github.com/mitchellh/go-testing-interface"
"github.com/hashicorp/consul/agent/proxycfg" "github.com/hashicorp/consul/agent/proxycfg"
"github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/agent/xds/proxysupport" "github.com/hashicorp/consul/agent/xds/proxysupport"
"github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/sdk/testutil"
testinf "github.com/mitchellh/go-testing-interface"
) )
func Test_makeLoadAssignment(t *testing.T) { func Test_makeLoadAssignment(t *testing.T) {
@ -579,10 +580,7 @@ func Test_endpointsFromSnapshot(t *testing.T) {
} }
// Need server just for logger dependency // Need server just for logger dependency
logger := testutil.Logger(t) s := Server{Logger: testutil.Logger(t)}
s := Server{
Logger: logger,
}
cInfo := connectionInfo{ cInfo := connectionInfo{
Token: "my-token", Token: "my-token",

View File

@ -9,12 +9,13 @@ import (
envoy "github.com/envoyproxy/go-control-plane/envoy/api/v2" envoy "github.com/envoyproxy/go-control-plane/envoy/api/v2"
"github.com/envoyproxy/go-control-plane/pkg/wellknown" "github.com/envoyproxy/go-control-plane/pkg/wellknown"
testinf "github.com/mitchellh/go-testing-interface"
"github.com/stretchr/testify/require"
"github.com/hashicorp/consul/agent/proxycfg" "github.com/hashicorp/consul/agent/proxycfg"
"github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/agent/xds/proxysupport" "github.com/hashicorp/consul/agent/xds/proxysupport"
"github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/sdk/testutil"
testinf "github.com/mitchellh/go-testing-interface"
"github.com/stretchr/testify/require"
) )
func TestListenersFromSnapshot(t *testing.T) { func TestListenersFromSnapshot(t *testing.T) {
@ -508,10 +509,7 @@ func TestListenersFromSnapshot(t *testing.T) {
} }
// Need server just for logger dependency // Need server just for logger dependency
logger := testutil.Logger(t) s := Server{Logger: testutil.Logger(t)}
s := Server{
Logger: logger,
}
cInfo := connectionInfo{ cInfo := connectionInfo{
Token: "my-token", Token: "my-token",

View File

@ -9,14 +9,15 @@ import (
envoy "github.com/envoyproxy/go-control-plane/envoy/api/v2" envoy "github.com/envoyproxy/go-control-plane/envoy/api/v2"
envoyroute "github.com/envoyproxy/go-control-plane/envoy/api/v2/route" envoyroute "github.com/envoyproxy/go-control-plane/envoy/api/v2/route"
"github.com/golang/protobuf/ptypes" "github.com/golang/protobuf/ptypes"
testinf "github.com/mitchellh/go-testing-interface"
"github.com/stretchr/testify/require"
"github.com/hashicorp/consul/agent/connect" "github.com/hashicorp/consul/agent/connect"
"github.com/hashicorp/consul/agent/consul/discoverychain" "github.com/hashicorp/consul/agent/consul/discoverychain"
"github.com/hashicorp/consul/agent/proxycfg" "github.com/hashicorp/consul/agent/proxycfg"
"github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/agent/xds/proxysupport" "github.com/hashicorp/consul/agent/xds/proxysupport"
"github.com/hashicorp/consul/sdk/testutil" "github.com/hashicorp/consul/sdk/testutil"
testinf "github.com/mitchellh/go-testing-interface"
"github.com/stretchr/testify/require"
) )
func TestRoutesFromSnapshot(t *testing.T) { func TestRoutesFromSnapshot(t *testing.T) {
@ -256,10 +257,7 @@ func TestRoutesFromSnapshot(t *testing.T) {
tt.setup(snap) tt.setup(snap)
} }
logger := testutil.Logger(t) s := Server{Logger: testutil.Logger(t)}
s := Server{
Logger: logger,
}
cInfo := connectionInfo{ cInfo := connectionInfo{
Token: "my-token", Token: "my-token",
ProxyFeatures: sf, ProxyFeatures: sf,

View File

@ -11,17 +11,17 @@ import (
envoycore "github.com/envoyproxy/go-control-plane/envoy/api/v2/core" envoycore "github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
envoydisco "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v2" envoydisco "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v2"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"github.com/hashicorp/consul/acl"
"github.com/hashicorp/consul/agent/proxycfg"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/logging"
"github.com/hashicorp/consul/tlsutil"
"github.com/hashicorp/go-hclog" "github.com/hashicorp/go-hclog"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata" "google.golang.org/grpc/metadata"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
"github.com/hashicorp/consul/acl"
"github.com/hashicorp/consul/agent/proxycfg"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/tlsutil"
) )
// ADSStream is a shorter way of referring to this thing... // ADSStream is a shorter way of referring to this thing...
@ -130,7 +130,6 @@ func (s *Server) Initialize() {
if s.AuthCheckFrequency == 0 { if s.AuthCheckFrequency == 0 {
s.AuthCheckFrequency = DefaultAuthCheckFrequency s.AuthCheckFrequency = DefaultAuthCheckFrequency
} }
s.Logger = s.Logger.Named(logging.Envoy)
} }
// StreamAggregatedResources implements // StreamAggregatedResources implements

View File

@ -89,7 +89,6 @@ func (m *testManager) AssertWatchCancelled(t *testing.T, proxyID structs.Service
} }
func TestServer_StreamAggregatedResources_BasicProtocol(t *testing.T) { func TestServer_StreamAggregatedResources_BasicProtocol(t *testing.T) {
logger := testutil.Logger(t)
mgr := newTestManager(t) mgr := newTestManager(t)
aclResolve := func(id string) (acl.Authorizer, error) { aclResolve := func(id string) (acl.Authorizer, error) {
// Allow all // Allow all
@ -99,7 +98,7 @@ func TestServer_StreamAggregatedResources_BasicProtocol(t *testing.T) {
defer envoy.Close() defer envoy.Close()
s := Server{ s := Server{
Logger: logger, Logger: testutil.Logger(t),
CfgMgr: mgr, CfgMgr: mgr,
ResolveToken: aclResolve, ResolveToken: aclResolve,
} }
@ -430,7 +429,6 @@ func TestServer_StreamAggregatedResources_ACLEnforcement(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
logger := testutil.Logger(t)
mgr := newTestManager(t) mgr := newTestManager(t)
aclResolve := func(id string) (acl.Authorizer, error) { aclResolve := func(id string) (acl.Authorizer, error) {
if !tt.defaultDeny { if !tt.defaultDeny {
@ -452,7 +450,7 @@ func TestServer_StreamAggregatedResources_ACLEnforcement(t *testing.T) {
defer envoy.Close() defer envoy.Close()
s := Server{ s := Server{
Logger: logger, Logger: testutil.Logger(t),
CfgMgr: mgr, CfgMgr: mgr,
ResolveToken: aclResolve, ResolveToken: aclResolve,
} }
@ -513,7 +511,6 @@ func TestServer_StreamAggregatedResources_ACLTokenDeleted_StreamTerminatedDuring
var validToken atomic.Value var validToken atomic.Value
validToken.Store(token) validToken.Store(token)
logger := testutil.Logger(t)
mgr := newTestManager(t) mgr := newTestManager(t)
aclResolve := func(id string) (acl.Authorizer, error) { aclResolve := func(id string) (acl.Authorizer, error) {
if token := validToken.Load(); token == nil || id != token.(string) { if token := validToken.Load(); token == nil || id != token.(string) {
@ -526,7 +523,7 @@ func TestServer_StreamAggregatedResources_ACLTokenDeleted_StreamTerminatedDuring
defer envoy.Close() defer envoy.Close()
s := Server{ s := Server{
Logger: logger, Logger: testutil.Logger(t),
CfgMgr: mgr, CfgMgr: mgr,
ResolveToken: aclResolve, ResolveToken: aclResolve,
AuthCheckFrequency: 1 * time.Hour, // make sure this doesn't kick in AuthCheckFrequency: 1 * time.Hour, // make sure this doesn't kick in
@ -608,7 +605,6 @@ func TestServer_StreamAggregatedResources_ACLTokenDeleted_StreamTerminatedInBack
var validToken atomic.Value var validToken atomic.Value
validToken.Store(token) validToken.Store(token)
logger := testutil.Logger(t)
mgr := newTestManager(t) mgr := newTestManager(t)
aclResolve := func(id string) (acl.Authorizer, error) { aclResolve := func(id string) (acl.Authorizer, error) {
if token := validToken.Load(); token == nil || id != token.(string) { if token := validToken.Load(); token == nil || id != token.(string) {
@ -621,7 +617,7 @@ func TestServer_StreamAggregatedResources_ACLTokenDeleted_StreamTerminatedInBack
defer envoy.Close() defer envoy.Close()
s := Server{ s := Server{
Logger: logger, Logger: testutil.Logger(t),
CfgMgr: mgr, CfgMgr: mgr,
ResolveToken: aclResolve, ResolveToken: aclResolve,
AuthCheckFrequency: 100 * time.Millisecond, // Make this short. AuthCheckFrequency: 100 * time.Millisecond, // Make this short.
@ -698,7 +694,6 @@ func TestServer_StreamAggregatedResources_ACLTokenDeleted_StreamTerminatedInBack
} }
func TestServer_StreamAggregatedResources_IngressEmptyResponse(t *testing.T) { func TestServer_StreamAggregatedResources_IngressEmptyResponse(t *testing.T) {
logger := testutil.Logger(t)
mgr := newTestManager(t) mgr := newTestManager(t)
aclResolve := func(id string) (acl.Authorizer, error) { aclResolve := func(id string) (acl.Authorizer, error) {
// Allow all // Allow all
@ -708,7 +703,7 @@ func TestServer_StreamAggregatedResources_IngressEmptyResponse(t *testing.T) {
defer envoy.Close() defer envoy.Close()
s := Server{ s := Server{
Logger: logger, Logger: testutil.Logger(t),
CfgMgr: mgr, CfgMgr: mgr,
ResolveToken: aclResolve, ResolveToken: aclResolve,
} }