From 4eaffe4c41ef409b4284f4bb2d0087979a735d6d Mon Sep 17 00:00:00 2001 From: Hans Hasselberg Date: Mon, 18 Mar 2019 17:06:16 +0100 Subject: [PATCH] agent: only use TestAgent when appropriate (#5502) --- agent/agent_test.go | 20 ++++++++++---------- agent/testagent.go | 15 --------------- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/agent/agent_test.go b/agent/agent_test.go index be3fcb579..260701210 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -2490,8 +2490,8 @@ func TestAgent_Service_Reap(t *testing.T) { } chkTypes := []*structs.CheckType{ &structs.CheckType{ - Status: api.HealthPassing, - TTL: 25 * time.Millisecond, + Status: api.HealthPassing, + TTL: 25 * time.Millisecond, DeregisterCriticalServiceAfter: 200 * time.Millisecond, }, } @@ -3584,8 +3584,8 @@ func TestAgent_ReloadConfigOutgoingRPCConfig(t *testing.T) { key_file = "../test/key/ourdomain.key" verify_server_hostname = false ` - a, err := NewUnstartedAgent(t, t.Name(), hcl) - require.NoError(t, err) + a := NewTestAgent(t, t.Name(), hcl) + defer a.Shutdown() tlsConf := a.tlsConfigurator.OutgoingRPCConfig() require.True(t, tlsConf.InsecureSkipVerify) require.Len(t, tlsConf.ClientCAs.Subjects(), 1) @@ -3619,11 +3619,11 @@ func TestAgent_ReloadConfigIncomingRPCConfig(t *testing.T) { key_file = "../test/key/ourdomain.key" verify_server_hostname = false ` - a, err := NewUnstartedAgent(t, t.Name(), hcl) - require.NoError(t, err) + a := NewTestAgent(t, t.Name(), hcl) + defer a.Shutdown() tlsConf := a.tlsConfigurator.IncomingRPCConfig() require.NotNil(t, tlsConf.GetConfigForClient) - tlsConf, err = tlsConf.GetConfigForClient(nil) + tlsConf, err := tlsConf.GetConfigForClient(nil) require.NoError(t, err) require.NotNil(t, tlsConf) require.True(t, tlsConf.InsecureSkipVerify) @@ -3659,8 +3659,8 @@ func TestAgent_ReloadConfigTLSConfigFailure(t *testing.T) { key_file = "../test/key/ourdomain.key" verify_server_hostname = false ` - a, err := NewUnstartedAgent(t, t.Name(), hcl) - require.NoError(t, err) + a := NewTestAgent(t, t.Name(), hcl) + defer a.Shutdown() tlsConf := a.tlsConfigurator.IncomingRPCConfig() hcl = ` @@ -3669,7 +3669,7 @@ func TestAgent_ReloadConfigTLSConfigFailure(t *testing.T) { ` c := TestConfig(config.Source{Name: t.Name(), Format: "hcl", Data: hcl}) require.Error(t, a.ReloadConfig(c)) - tlsConf, err = tlsConf.GetConfigForClient(nil) + tlsConf, err := tlsConf.GetConfigForClient(nil) require.NoError(t, err) require.Equal(t, tls.NoClientCert, tlsConf.ClientAuth) require.Len(t, tlsConf.ClientCAs.Subjects(), 1) diff --git a/agent/testagent.go b/agent/testagent.go index 64343f071..c0c8b7669 100644 --- a/agent/testagent.go +++ b/agent/testagent.go @@ -18,17 +18,14 @@ import ( metrics "github.com/armon/go-metrics" uuid "github.com/hashicorp/go-uuid" - "github.com/hashicorp/consul/agent/ae" "github.com/hashicorp/consul/agent/config" "github.com/hashicorp/consul/agent/connect" "github.com/hashicorp/consul/agent/consul" - "github.com/hashicorp/consul/agent/local" "github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/consul/api" "github.com/hashicorp/consul/lib/freeport" "github.com/hashicorp/consul/logger" "github.com/hashicorp/consul/testutil/retry" - "github.com/hashicorp/consul/tlsutil" "github.com/stretchr/testify/require" ) @@ -111,15 +108,6 @@ func NewUnstartedAgent(t *testing.T, name string, hcl string) (*Agent, error) { if err != nil { return nil, err } - a.State = local.NewState(LocalConfig(c), a.logger, a.tokens) - a.sync = ae.NewStateSyncer(a.State, c.AEInterval, a.shutdownCh, a.logger) - a.delegate = &consul.Client{} - a.State.TriggerSyncChanges = a.sync.SyncChanges.Trigger - tlsConfigurator, err := tlsutil.NewConfigurator(c.ToTLSUtilConfig(), nil) - if err != nil { - return nil, err - } - a.tlsConfigurator = tlsConfigurator return a, nil } @@ -169,9 +157,6 @@ func (a *TestAgent) Start(t *testing.T) *TestAgent { agent.LogWriter = a.LogWriter agent.logger = log.New(logOutput, a.Name+" - ", log.LstdFlags|log.Lmicroseconds) agent.MemSink = metrics.NewInmemSink(1*time.Second, time.Minute) - tlsConfigurator, err := tlsutil.NewConfigurator(a.Config.ToTLSUtilConfig(), nil) - require.NoError(err) - agent.tlsConfigurator = tlsConfigurator // we need the err var in the next exit condition if err := agent.Start(); err == nil {