mirror of https://github.com/status-im/consul.git
Convert the remaining calls to NewTestAgentWithFields
After removing the t.Name() parameter with sed, convert the last few tests which use a custom name to call NewTestAgentWithFields instead.
This commit is contained in:
parent
475659a132
commit
f9f6b14533
|
@ -1773,9 +1773,9 @@ func TestAgent_ForceLeave_ACLDeny(t *testing.T) {
|
|||
|
||||
func TestAgent_ForceLeavePrune(t *testing.T) {
|
||||
t.Parallel()
|
||||
a1 := NewTestAgent(t, t.Name()+"-a1", "")
|
||||
a1 := NewTestAgentWithFields(t, true, TestAgent{Name: "Agent1"})
|
||||
defer a1.Shutdown()
|
||||
a2 := NewTestAgent(t, t.Name()+"-a2", "")
|
||||
a2 := NewTestAgentWithFields(t, true, TestAgent{Name: "Agent2"})
|
||||
testrpc.WaitForLeader(t, a1.RPC, "dc1")
|
||||
testrpc.WaitForLeader(t, a2.RPC, "dc1")
|
||||
|
||||
|
@ -5236,17 +5236,17 @@ func TestAgentConnectCALeafCert_secondaryDC_good(t *testing.T) {
|
|||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
a1 := NewTestAgent(t, t.Name()+"-dc1", `
|
||||
a1 := NewTestAgentWithFields(t, true, TestAgent{Name: "dc1", HCL: `
|
||||
datacenter = "dc1"
|
||||
primary_datacenter = "dc1"
|
||||
`)
|
||||
`})
|
||||
defer a1.Shutdown()
|
||||
testrpc.WaitForTestAgent(t, a1.RPC, "dc1")
|
||||
|
||||
a2 := NewTestAgent(t, t.Name()+"-dc2", `
|
||||
a2 := NewTestAgentWithFields(t, true, TestAgent{Name: "dc2", HCL: `
|
||||
datacenter = "dc2"
|
||||
primary_datacenter = "dc1"
|
||||
`)
|
||||
`})
|
||||
defer a2.Shutdown()
|
||||
testrpc.WaitForTestAgent(t, a2.RPC, "dc2")
|
||||
|
||||
|
|
|
@ -80,21 +80,6 @@ func requireCheckMissingMap(t *testing.T, m interface{}, id types.CheckID) {
|
|||
require.NotContains(t, m, structs.NewCheckID(id, nil), "have check %q (expected missing)", id)
|
||||
}
|
||||
|
||||
func externalIP() (string, error) {
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Unable to lookup network interfaces: %v", err)
|
||||
}
|
||||
for _, a := range addrs {
|
||||
if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
|
||||
if ipnet.IP.To4() != nil {
|
||||
return ipnet.IP.String(), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("Unable to find a non-loopback interface")
|
||||
}
|
||||
|
||||
func TestAgent_MultiStartStop(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
t.Run("", func(t *testing.T) {
|
||||
|
@ -138,7 +123,7 @@ func TestAgent_ConnectClusterIDConfig(t *testing.T) {
|
|||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
a := NewTestAgentWithFields(t, false, TestAgent{HCL: tt.hcl})
|
||||
a := TestAgent{HCL: tt.hcl}
|
||||
err := a.Start(t)
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
|
@ -4046,11 +4031,11 @@ func TestAgentCache_serviceInConfigFile_initialFetchErrors_Issue6521(t *testing.
|
|||
// index for the next query from 0 to 1 for all queries, when it should
|
||||
// have not done so for queries that errored.
|
||||
|
||||
a1 := NewTestAgent(t, t.Name()+"-a1", "")
|
||||
a1 := NewTestAgentWithFields(t, true, TestAgent{Name: "Agent1"})
|
||||
defer a1.Shutdown()
|
||||
testrpc.WaitForLeader(t, a1.RPC, "dc1")
|
||||
|
||||
a2 := NewTestAgent(t, t.Name()+"-a2", `
|
||||
a2 := NewTestAgentWithFields(t, true, TestAgent{Name: "Agent2", HCL: `
|
||||
server = false
|
||||
bootstrap = false
|
||||
services {
|
||||
|
@ -4075,7 +4060,7 @@ services {
|
|||
sidecar_service {}
|
||||
}
|
||||
}
|
||||
`)
|
||||
`})
|
||||
defer a2.Shutdown()
|
||||
|
||||
// Starting a client agent disconnected from a server with services.
|
||||
|
@ -4142,7 +4127,7 @@ func TestAgent_JoinWAN_viaMeshGateway(t *testing.T) {
|
|||
secondaryRPCPorts := freeport.MustTake(2)
|
||||
defer freeport.Return(secondaryRPCPorts)
|
||||
|
||||
a1 := NewTestAgent(t, t.Name()+"-bob", `
|
||||
a1 := NewTestAgentWithFields(t, true, TestAgent{Name: "bob", HCL: `
|
||||
domain = "consul"
|
||||
node_name = "bob"
|
||||
datacenter = "dc1"
|
||||
|
@ -4159,7 +4144,7 @@ func TestAgent_JoinWAN_viaMeshGateway(t *testing.T) {
|
|||
enabled = true
|
||||
enable_mesh_gateway_wan_federation = true
|
||||
}
|
||||
`)
|
||||
`})
|
||||
defer a1.Shutdown()
|
||||
testrpc.WaitForTestAgent(t, a1.RPC, "dc1")
|
||||
|
||||
|
@ -4227,7 +4212,7 @@ func TestAgent_JoinWAN_viaMeshGateway(t *testing.T) {
|
|||
require.NotEmpty(r, a1.PickRandomMeshGatewaySuitableForDialing("dc1"))
|
||||
})
|
||||
|
||||
a2 := NewTestAgent(t, t.Name()+"-betty", `
|
||||
a2 := NewTestAgentWithFields(t, true, TestAgent{Name: "betty", HCL: `
|
||||
domain = "consul"
|
||||
node_name = "betty"
|
||||
datacenter = "dc2"
|
||||
|
@ -4240,19 +4225,19 @@ func TestAgent_JoinWAN_viaMeshGateway(t *testing.T) {
|
|||
verify_outgoing = true
|
||||
verify_server_hostname = true
|
||||
ports {
|
||||
server = `+strconv.Itoa(secondaryRPCPorts[0])+`
|
||||
server = ` + strconv.Itoa(secondaryRPCPorts[0]) + `
|
||||
}
|
||||
# wanfed
|
||||
primary_gateways = ["`+gwAddr+`"]
|
||||
primary_gateways = ["` + gwAddr + `"]
|
||||
connect {
|
||||
enabled = true
|
||||
enable_mesh_gateway_wan_federation = true
|
||||
}
|
||||
`)
|
||||
`})
|
||||
defer a2.Shutdown()
|
||||
testrpc.WaitForTestAgent(t, a2.RPC, "dc2")
|
||||
|
||||
a3 := NewTestAgent(t, t.Name()+"-bonnie", `
|
||||
a3 := NewTestAgentWithFields(t, true, TestAgent{Name: "bonnie", HCL: `
|
||||
domain = "consul"
|
||||
node_name = "bonnie"
|
||||
datacenter = "dc3"
|
||||
|
@ -4265,15 +4250,15 @@ func TestAgent_JoinWAN_viaMeshGateway(t *testing.T) {
|
|||
verify_outgoing = true
|
||||
verify_server_hostname = true
|
||||
ports {
|
||||
server = `+strconv.Itoa(secondaryRPCPorts[1])+`
|
||||
server = ` + strconv.Itoa(secondaryRPCPorts[1]) + `
|
||||
}
|
||||
# wanfed
|
||||
primary_gateways = ["`+gwAddr+`"]
|
||||
primary_gateways = ["` + gwAddr + `"]
|
||||
connect {
|
||||
enabled = true
|
||||
enable_mesh_gateway_wan_federation = true
|
||||
}
|
||||
`)
|
||||
`})
|
||||
defer a3.Shutdown()
|
||||
testrpc.WaitForTestAgent(t, a3.RPC, "dc3")
|
||||
|
||||
|
|
|
@ -325,7 +325,7 @@ func TestAgent_sidecarServiceFromNodeService(t *testing.T) {
|
|||
}
|
||||
|
||||
require := require.New(t)
|
||||
a := NewTestAgentWithFields(t, "jones", hcl)
|
||||
a := NewTestAgentWithFields(t, true, TestAgent{Name: "jones", HCL: hcl})
|
||||
defer a.Shutdown()
|
||||
|
||||
if tt.preRegister != nil {
|
||||
|
|
|
@ -122,15 +122,7 @@ func (a *TestAgent) Start(t *testing.T) (err error) {
|
|||
}
|
||||
|
||||
name := a.Name
|
||||
// Many tests set Name to t.Name(), which takes up a lot of space at the
|
||||
// start of the log messages. The only time we need to care about a name is
|
||||
// when a test using multiple TestAgents.
|
||||
// As a temporary workaround we ignore the default name and use a shorter
|
||||
// default value. Tests which set a custom name for multiple agents will
|
||||
// use the provided name.
|
||||
// TODO: remove TestAgent.Name and accept a name arg on Start, to remove
|
||||
// this workaround.
|
||||
if name == "" || name == t.Name() {
|
||||
if name == "" {
|
||||
name = "TestAgent"
|
||||
}
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ func TestCatalogListNodesCommand_verticalBar(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
nodeName := "name|with|bars"
|
||||
a := agent.NewTestAgent(t, "", `node_name = "`+nodeName+`"`)
|
||||
a := agent.NewTestAgent(t, `node_name = "`+nodeName+`"`)
|
||||
defer a.Shutdown()
|
||||
|
||||
testrpc.WaitForTestAgent(t, a.RPC, "dc1")
|
||||
|
|
|
@ -76,9 +76,9 @@ func TestForceLeaveCommand_NoNodeWithName(t *testing.T) {
|
|||
|
||||
func TestForceLeaveCommand_prune(t *testing.T) {
|
||||
t.Parallel()
|
||||
a1 := agent.NewTestAgent(t, t.Name()+"-a1", ``)
|
||||
a1 := agent.StartTestAgent(t, agent.TestAgent{Name: "Agent1"})
|
||||
defer a1.Shutdown()
|
||||
a2 := agent.NewTestAgent(t, t.Name()+"-a2", ``)
|
||||
a2 := agent.StartTestAgent(t, agent.TestAgent{Name: "Agent2"})
|
||||
defer a2.Shutdown()
|
||||
|
||||
_, err := a2.JoinLAN([]string{a1.Config.SerfBindAddrLAN.String()})
|
||||
|
|
|
@ -125,7 +125,7 @@ func TestMembersCommand_verticalBar(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
nodeName := "name|with|bars"
|
||||
a := agent.NewTestAgent(t, "", `node_name = "`+nodeName+`"`)
|
||||
a := agent.NewTestAgent(t, `node_name = "`+nodeName+`"`)
|
||||
defer a.Shutdown()
|
||||
|
||||
ui := cli.NewMockUi()
|
||||
|
|
|
@ -43,7 +43,7 @@ func TestOperatorRaftListPeersCommand_verticalBar(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
nodeName := "name|with|bars"
|
||||
a := agent.NewTestAgent(t, "", `node_name = "`+nodeName+`"`)
|
||||
a := agent.NewTestAgent(t, `node_name = "`+nodeName+`"`)
|
||||
defer a.Shutdown()
|
||||
|
||||
ui := cli.NewMockUi()
|
||||
|
|
|
@ -81,7 +81,7 @@ func TestUpstreamResolverFuncFromClient(t *testing.T) {
|
|||
func TestAgentConfigWatcherSidecarProxy(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
a := agent.NewTestAgent(t, "agent_smith", ``)
|
||||
a := agent.StartTestAgent(t, agent.TestAgent{Name: "agent_smith"})
|
||||
defer a.Shutdown()
|
||||
|
||||
client := a.Client()
|
||||
|
|
|
@ -42,7 +42,7 @@ func TestStaticResolver_Resolve(t *testing.T) {
|
|||
|
||||
func TestConsulResolver_Resolve(t *testing.T) {
|
||||
// Setup a local test agent to query
|
||||
agent := agent.NewTestAgent(t, "test-consul", "")
|
||||
agent := agent.StartTestAgent(t, agent.TestAgent{Name: "test-consul"})
|
||||
defer agent.Shutdown()
|
||||
|
||||
cfg := api.DefaultConfig()
|
||||
|
|
|
@ -127,7 +127,7 @@ func TestService_Dial(t *testing.T) {
|
|||
func TestService_ServerTLSConfig(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
a := agent.NewTestAgent(t, "007", "")
|
||||
a := agent.StartTestAgent(t, agent.TestAgent{Name: "007"})
|
||||
defer a.Shutdown()
|
||||
testrpc.WaitForTestAgent(t, a.RPC, "dc1")
|
||||
client := a.Client()
|
||||
|
|
|
@ -152,7 +152,7 @@ func TestServerSideVerifier(t *testing.T) {
|
|||
apiCA2 := testCertPEMBlock(t, apiCA2PEM)
|
||||
|
||||
// Setup a local test agent to query
|
||||
agent := agent.NewTestAgent(t, "test-consul", "")
|
||||
agent := agent.StartTestAgent(t, agent.TestAgent{Name: "test-consul"})
|
||||
defer agent.Shutdown()
|
||||
testrpc.WaitForTestAgent(t, agent.RPC, "dc1")
|
||||
|
||||
|
|
Loading…
Reference in New Issue