test: rename *Config vars to 'cfg'

'c' is ambigous since Command also uses this
and we want to use 'config' as a package name.
This commit is contained in:
Frank Schroeder 2017-05-22 13:03:59 +02:00
parent 06677708cf
commit 141efd9588
No known key found for this signature in database
GPG Key ID: 4D65C6EAEC87DECD
22 changed files with 423 additions and 426 deletions

View File

@ -16,11 +16,11 @@ import (
func TestACL_Bad_Config(t *testing.T) {
t.Parallel()
c := TestConfig()
c.ACLDownPolicy = "nope"
c.DataDir = testutil.TempDir(t, "agent")
cfg := TestConfig()
cfg.ACLDownPolicy = "nope"
cfg.DataDir = testutil.TempDir(t, "agent")
_, err := NewAgent(c)
_, err := NewAgent(cfg)
if err == nil || !strings.Contains(err.Error(), "invalid ACL down policy") {
t.Fatalf("err: %v", err)
}
@ -39,9 +39,9 @@ func (m *MockServer) GetPolicy(args *structs.ACLPolicyRequest, reply *structs.AC
func TestACL_Version8(t *testing.T) {
t.Parallel()
config := TestConfig()
config.ACLEnforceVersion8 = &BoolFalse
a := NewTestAgent(t.Name(), config)
cfg := TestConfig()
cfg.ACLEnforceVersion8 = &BoolFalse
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
m := MockServer{}
@ -61,10 +61,10 @@ func TestACL_Version8(t *testing.T) {
func TestACL_Disabled(t *testing.T) {
t.Parallel()
config := TestConfig()
config.ACLDisabledTTL = 10 * time.Millisecond
config.ACLEnforceVersion8 = &BoolTrue
a := NewTestAgent(t.Name(), config)
cfg := TestConfig()
cfg.ACLDisabledTTL = 10 * time.Millisecond
cfg.ACLEnforceVersion8 = &BoolTrue
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
m := MockServer{}
@ -100,7 +100,7 @@ func TestACL_Disabled(t *testing.T) {
// Wait the waiting period and make sure it checks again. Do a few tries
// to make sure we don't think it's disabled.
time.Sleep(2 * config.ACLDisabledTTL)
time.Sleep(2 * cfg.ACLDisabledTTL)
for i := 0; i < 10; i++ {
_, err := a.resolveToken("nope")
if err == nil || !strings.Contains(err.Error(), aclNotFound) {
@ -114,11 +114,10 @@ func TestACL_Disabled(t *testing.T) {
func TestACL_Special_IDs(t *testing.T) {
t.Parallel()
config := TestConfig()
config.ACLEnforceVersion8 = &BoolTrue
config.ACLAgentMasterToken = "towel"
a := NewTestAgent(t.Name(), config)
cfg := TestConfig()
cfg.ACLEnforceVersion8 = &BoolTrue
cfg.ACLAgentMasterToken = "towel"
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
m := MockServer{}
@ -157,21 +156,21 @@ func TestACL_Special_IDs(t *testing.T) {
if acl == nil {
t.Fatalf("should not be nil")
}
if !acl.AgentRead(config.NodeName) {
if !acl.AgentRead(cfg.NodeName) {
t.Fatalf("should be able to read agent")
}
if !acl.AgentWrite(config.NodeName) {
if !acl.AgentWrite(cfg.NodeName) {
t.Fatalf("should be able to write agent")
}
}
func TestACL_Down_Deny(t *testing.T) {
t.Parallel()
config := TestConfig()
config.ACLDownPolicy = "deny"
config.ACLEnforceVersion8 = &BoolTrue
cfg := TestConfig()
cfg.ACLDownPolicy = "deny"
cfg.ACLEnforceVersion8 = &BoolTrue
a := NewTestAgent(t.Name(), config)
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
m := MockServer{}
@ -190,18 +189,18 @@ func TestACL_Down_Deny(t *testing.T) {
if acl == nil {
t.Fatalf("should not be nil")
}
if acl.AgentRead(config.NodeName) {
if acl.AgentRead(cfg.NodeName) {
t.Fatalf("should deny")
}
}
func TestACL_Down_Allow(t *testing.T) {
t.Parallel()
config := TestConfig()
config.ACLDownPolicy = "allow"
config.ACLEnforceVersion8 = &BoolTrue
cfg := TestConfig()
cfg.ACLDownPolicy = "allow"
cfg.ACLEnforceVersion8 = &BoolTrue
a := NewTestAgent(t.Name(), config)
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
m := MockServer{}
@ -220,18 +219,18 @@ func TestACL_Down_Allow(t *testing.T) {
if acl == nil {
t.Fatalf("should not be nil")
}
if !acl.AgentRead(config.NodeName) {
if !acl.AgentRead(cfg.NodeName) {
t.Fatalf("should allow")
}
}
func TestACL_Down_Extend(t *testing.T) {
t.Parallel()
config := TestConfig()
config.ACLDownPolicy = "extend-cache"
config.ACLEnforceVersion8 = &BoolTrue
cfg := TestConfig()
cfg.ACLDownPolicy = "extend-cache"
cfg.ACLEnforceVersion8 = &BoolTrue
a := NewTestAgent(t.Name(), config)
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
m := MockServer{}
@ -246,7 +245,7 @@ func TestACL_Down_Extend(t *testing.T) {
Policy: &rawacl.Policy{
Agents: []*rawacl.AgentPolicy{
&rawacl.AgentPolicy{
Node: config.NodeName,
Node: cfg.NodeName,
Policy: "read",
},
},
@ -261,10 +260,10 @@ func TestACL_Down_Extend(t *testing.T) {
if acl == nil {
t.Fatalf("should not be nil")
}
if !acl.AgentRead(config.NodeName) {
if !acl.AgentRead(cfg.NodeName) {
t.Fatalf("should allow")
}
if acl.AgentWrite(config.NodeName) {
if acl.AgentWrite(cfg.NodeName) {
t.Fatalf("should deny")
}
@ -279,10 +278,10 @@ func TestACL_Down_Extend(t *testing.T) {
if acl == nil {
t.Fatalf("should not be nil")
}
if acl.AgentRead(config.NodeName) {
if acl.AgentRead(cfg.NodeName) {
t.Fatalf("should deny")
}
if acl.AgentWrite(config.NodeName) {
if acl.AgentWrite(cfg.NodeName) {
t.Fatalf("should deny")
}
@ -295,20 +294,20 @@ func TestACL_Down_Extend(t *testing.T) {
if acl == nil {
t.Fatalf("should not be nil")
}
if !acl.AgentRead(config.NodeName) {
if !acl.AgentRead(cfg.NodeName) {
t.Fatalf("should allow")
}
if acl.AgentWrite(config.NodeName) {
if acl.AgentWrite(cfg.NodeName) {
t.Fatalf("should deny")
}
}
func TestACL_Cache(t *testing.T) {
t.Parallel()
config := TestConfig()
config.ACLEnforceVersion8 = &BoolTrue
cfg := TestConfig()
cfg.ACLEnforceVersion8 = &BoolTrue
a := NewTestAgent(t.Name(), config)
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
m := MockServer{}
@ -324,7 +323,7 @@ func TestACL_Cache(t *testing.T) {
Policy: &rawacl.Policy{
Agents: []*rawacl.AgentPolicy{
&rawacl.AgentPolicy{
Node: config.NodeName,
Node: cfg.NodeName,
Policy: "read",
},
},
@ -340,10 +339,10 @@ func TestACL_Cache(t *testing.T) {
if acl == nil {
t.Fatalf("should not be nil")
}
if !acl.AgentRead(config.NodeName) {
if !acl.AgentRead(cfg.NodeName) {
t.Fatalf("should allow")
}
if acl.AgentWrite(config.NodeName) {
if acl.AgentWrite(cfg.NodeName) {
t.Fatalf("should deny")
}
if acl.NodeRead("nope") {
@ -362,10 +361,10 @@ func TestACL_Cache(t *testing.T) {
if acl == nil {
t.Fatalf("should not be nil")
}
if !acl.AgentRead(config.NodeName) {
if !acl.AgentRead(cfg.NodeName) {
t.Fatalf("should allow")
}
if acl.AgentWrite(config.NodeName) {
if acl.AgentWrite(cfg.NodeName) {
t.Fatalf("should deny")
}
if acl.NodeRead("nope") {
@ -391,7 +390,7 @@ func TestACL_Cache(t *testing.T) {
Policy: &rawacl.Policy{
Agents: []*rawacl.AgentPolicy{
&rawacl.AgentPolicy{
Node: config.NodeName,
Node: cfg.NodeName,
Policy: "write",
},
},
@ -407,10 +406,10 @@ func TestACL_Cache(t *testing.T) {
if acl == nil {
t.Fatalf("should not be nil")
}
if !acl.AgentRead(config.NodeName) {
if !acl.AgentRead(cfg.NodeName) {
t.Fatalf("should allow")
}
if !acl.AgentWrite(config.NodeName) {
if !acl.AgentWrite(cfg.NodeName) {
t.Fatalf("should allow")
}
if acl.NodeRead("nope") {
@ -437,10 +436,10 @@ func TestACL_Cache(t *testing.T) {
if acl == nil {
t.Fatalf("should not be nil")
}
if !acl.AgentRead(config.NodeName) {
if !acl.AgentRead(cfg.NodeName) {
t.Fatalf("should allow")
}
if !acl.AgentWrite(config.NodeName) {
if !acl.AgentWrite(cfg.NodeName) {
t.Fatalf("should allow")
}
if acl.NodeRead("nope") {
@ -487,10 +486,10 @@ func catalogPolicy(req *structs.ACLPolicyRequest, reply *structs.ACLPolicy) erro
func TestACL_vetServiceRegister(t *testing.T) {
t.Parallel()
config := TestConfig()
config.ACLEnforceVersion8 = &BoolTrue
cfg := TestConfig()
cfg.ACLEnforceVersion8 = &BoolTrue
a := NewTestAgent(t.Name(), config)
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
m := MockServer{catalogPolicy}
@ -533,10 +532,10 @@ func TestACL_vetServiceRegister(t *testing.T) {
func TestACL_vetServiceUpdate(t *testing.T) {
t.Parallel()
config := TestConfig()
config.ACLEnforceVersion8 = &BoolTrue
cfg := TestConfig()
cfg.ACLEnforceVersion8 = &BoolTrue
a := NewTestAgent(t.Name(), config)
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
m := MockServer{catalogPolicy}
@ -569,10 +568,10 @@ func TestACL_vetServiceUpdate(t *testing.T) {
func TestACL_vetCheckRegister(t *testing.T) {
t.Parallel()
config := TestConfig()
config.ACLEnforceVersion8 = &BoolTrue
cfg := TestConfig()
cfg.ACLEnforceVersion8 = &BoolTrue
a := NewTestAgent(t.Name(), config)
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
m := MockServer{catalogPolicy}
@ -652,10 +651,10 @@ func TestACL_vetCheckRegister(t *testing.T) {
func TestACL_vetCheckUpdate(t *testing.T) {
t.Parallel()
config := TestConfig()
config.ACLEnforceVersion8 = &BoolTrue
cfg := TestConfig()
cfg.ACLEnforceVersion8 = &BoolTrue
a := NewTestAgent(t.Name(), config)
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
m := MockServer{catalogPolicy}
@ -708,10 +707,10 @@ func TestACL_vetCheckUpdate(t *testing.T) {
func TestACL_filterMembers(t *testing.T) {
t.Parallel()
config := TestConfig()
config.ACLEnforceVersion8 = &BoolTrue
cfg := TestConfig()
cfg.ACLEnforceVersion8 = &BoolTrue
a := NewTestAgent(t.Name(), config)
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
m := MockServer{catalogPolicy}
@ -744,10 +743,10 @@ func TestACL_filterMembers(t *testing.T) {
func TestACL_filterServices(t *testing.T) {
t.Parallel()
config := TestConfig()
config.ACLEnforceVersion8 = &BoolTrue
cfg := TestConfig()
cfg.ACLEnforceVersion8 = &BoolTrue
a := NewTestAgent(t.Name(), config)
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
m := MockServer{catalogPolicy}
@ -775,10 +774,10 @@ func TestACL_filterServices(t *testing.T) {
func TestACL_filterChecks(t *testing.T) {
t.Parallel()
config := TestConfig()
config.ACLEnforceVersion8 = &BoolTrue
cfg := TestConfig()
cfg.ACLEnforceVersion8 = &BoolTrue
a := NewTestAgent(t.Name(), config)
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
m := MockServer{catalogPolicy}

View File

@ -164,9 +164,9 @@ func TestAgent_Checks_ACLFilter(t *testing.T) {
func TestAgent_Self(t *testing.T) {
t.Parallel()
conf := TestConfig()
conf.Meta = map[string]string{"somekey": "somevalue"}
a := NewTestAgent(t.Name(), conf)
cfg := TestConfig()
cfg.Meta = map[string]string{"somekey": "somevalue"}
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
req, _ := http.NewRequest("GET", "/v1/agent/self", nil)
@ -191,8 +191,8 @@ func TestAgent_Self(t *testing.T) {
if !reflect.DeepEqual(c, val.Coord) {
t.Fatalf("coordinates are not equal: %v != %v", c, val.Coord)
}
if !reflect.DeepEqual(conf.Meta, val.Meta) {
t.Fatalf("meta fields are not equal: %v != %v", conf.Meta, val.Meta)
if !reflect.DeepEqual(cfg.Meta, val.Meta) {
t.Fatalf("meta fields are not equal: %v != %v", cfg.Meta, val.Meta)
}
// Make sure there's nothing called "token" that's leaked.
@ -235,7 +235,7 @@ func TestAgent_Self_ACLDeny(t *testing.T) {
func TestAgent_Reload(t *testing.T) {
t.Parallel()
conf := TestConfig()
cfg := TestConfig()
tmpDir := testutil.TempDir(t, "consul")
defer os.RemoveAll(tmpDir)
@ -267,7 +267,7 @@ func TestAgent_Reload(t *testing.T) {
"-server",
"-bind", "127.0.0.1",
"-data-dir", tmpDir,
"-http-port", fmt.Sprintf("%d", conf.Ports.HTTP),
"-http-port", fmt.Sprintf("%d", cfg.Ports.HTTP),
"-config-file", tmpFile.Name(),
}
@ -495,10 +495,10 @@ func TestAgent_Leave(t *testing.T) {
a1 := NewTestAgent(t.Name(), nil)
defer a1.Shutdown()
conf2 := TestConfig()
conf2.Server = false
conf2.Bootstrap = false
a2 := NewTestAgent(t.Name(), conf2)
cfg2 := TestConfig()
cfg2.Server = false
cfg2.Bootstrap = false
a2 := NewTestAgent(t.Name(), cfg2)
defer a2.Shutdown()
// Join first

View File

@ -80,14 +80,14 @@ func TestAgent_CheckSerfBindAddrsSettings(t *testing.T) {
t.Skip("skip test on macOS to avoid firewall warning dialog")
}
c := TestConfig()
cfg := TestConfig()
ip, err := externalIP()
if err != nil {
t.Fatalf("Unable to get a non-loopback IP: %v", err)
}
c.SerfLanBindAddr = ip
c.SerfWanBindAddr = ip
a := NewTestAgent(t.Name(), c)
cfg.SerfLanBindAddr = ip
cfg.SerfWanBindAddr = ip
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
serfWanBind := a.consulConfig().SerfWANConfig.MemberlistConfig.BindAddr
@ -102,11 +102,11 @@ func TestAgent_CheckSerfBindAddrsSettings(t *testing.T) {
}
func TestAgent_CheckAdvertiseAddrsSettings(t *testing.T) {
t.Parallel()
c := TestConfig()
c.AdvertiseAddrs.SerfLan, _ = net.ResolveTCPAddr("tcp", "127.0.0.42:1233")
c.AdvertiseAddrs.SerfWan, _ = net.ResolveTCPAddr("tcp", "127.0.0.43:1234")
c.AdvertiseAddrs.RPC, _ = net.ResolveTCPAddr("tcp", "127.0.0.44:1235")
a := NewTestAgent(t.Name(), c)
cfg := TestConfig()
cfg.AdvertiseAddrs.SerfLan, _ = net.ResolveTCPAddr("tcp", "127.0.0.42:1233")
cfg.AdvertiseAddrs.SerfWan, _ = net.ResolveTCPAddr("tcp", "127.0.0.43:1234")
cfg.AdvertiseAddrs.RPC, _ = net.ResolveTCPAddr("tcp", "127.0.0.44:1235")
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
serfLanAddr := a.consulConfig().SerfLANConfig.MemberlistConfig.AdvertiseAddr
@ -126,8 +126,8 @@ func TestAgent_CheckAdvertiseAddrsSettings(t *testing.T) {
t.Fatalf("SerfWan is not properly set to '1234': %d", serfWanPort)
}
rpc := a.consulConfig().RPCAdvertise
if rpc != c.AdvertiseAddrs.RPC {
t.Fatalf("RPC is not properly set to %v: %s", c.AdvertiseAddrs.RPC, rpc)
if rpc != cfg.AdvertiseAddrs.RPC {
t.Fatalf("RPC is not properly set to %v: %s", cfg.AdvertiseAddrs.RPC, rpc)
}
expected := map[string]string{
"lan": a.Config.AdvertiseAddr,
@ -142,10 +142,10 @@ func TestAgent_CheckPerformanceSettings(t *testing.T) {
t.Parallel()
// Try a default config.
{
c := TestConfig()
c.Bootstrap = false
c.ConsulConfig = nil
a := NewTestAgent(t.Name(), c)
cfg := TestConfig()
cfg.Bootstrap = false
cfg.ConsulConfig = nil
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
raftMult := time.Duration(consul.DefaultRaftMultiplier)
@ -160,10 +160,10 @@ func TestAgent_CheckPerformanceSettings(t *testing.T) {
// Try a multiplier.
{
c := TestConfig()
c.Bootstrap = false
c.Performance.RaftMultiplier = 99
a := NewTestAgent(t.Name(), c)
cfg := TestConfig()
cfg.Bootstrap = false
cfg.Performance.RaftMultiplier = 99
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
const raftMult time.Duration = 99
@ -195,10 +195,10 @@ func TestAgent_ReconnectConfigSettings(t *testing.T) {
}()
func() {
c := TestConfig()
c.ReconnectTimeoutLan = 24 * time.Hour
c.ReconnectTimeoutWan = 36 * time.Hour
a := NewTestAgent(t.Name(), c)
cfg := TestConfig()
cfg.ReconnectTimeoutLan = 24 * time.Hour
cfg.ReconnectTimeoutWan = 36 * time.Hour
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
lan := a.consulConfig().SerfLANConfig.ReconnectTimeout
@ -215,9 +215,9 @@ func TestAgent_ReconnectConfigSettings(t *testing.T) {
func TestAgent_setupNodeID(t *testing.T) {
t.Parallel()
c := TestConfig()
c.NodeID = ""
a := NewTestAgent(t.Name(), c)
cfg := TestConfig()
cfg.NodeID = ""
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
// The auto-assigned ID should be valid.
@ -227,8 +227,8 @@ func TestAgent_setupNodeID(t *testing.T) {
}
// Running again should get the same ID (persisted in the file).
c.NodeID = ""
if err := a.setupNodeID(c); err != nil {
cfg.NodeID = ""
if err := a.setupNodeID(cfg); err != nil {
t.Fatalf("err: %v", err)
}
if newID := a.consulConfig().NodeID; id != newID {
@ -236,8 +236,8 @@ func TestAgent_setupNodeID(t *testing.T) {
}
// Set an invalid ID via.Config.
c.NodeID = types.NodeID("nope")
err := a.setupNodeID(c)
cfg.NodeID = types.NodeID("nope")
err := a.setupNodeID(cfg)
if err == nil || !strings.Contains(err.Error(), "uuid string is wrong length") {
t.Fatalf("err: %v", err)
}
@ -247,8 +247,8 @@ func TestAgent_setupNodeID(t *testing.T) {
if err != nil {
t.Fatalf("err: %v", err)
}
c.NodeID = types.NodeID(strings.ToUpper(newID))
if err := a.setupNodeID(c); err != nil {
cfg.NodeID = types.NodeID(strings.ToUpper(newID))
if err := a.setupNodeID(cfg); err != nil {
t.Fatalf("err: %v", err)
}
if id := a.consulConfig().NodeID; string(id) != newID {
@ -256,12 +256,12 @@ func TestAgent_setupNodeID(t *testing.T) {
}
// Set an invalid ID via the file.
fileID := filepath.Join(c.DataDir, "node-id")
fileID := filepath.Join(cfg.DataDir, "node-id")
if err := ioutil.WriteFile(fileID, []byte("adf4238a!882b!9ddc!4a9d!5b6758e4159e"), 0600); err != nil {
t.Fatalf("err: %v", err)
}
c.NodeID = ""
err = a.setupNodeID(c)
cfg.NodeID = ""
err = a.setupNodeID(cfg)
if err == nil || !strings.Contains(err.Error(), "uuid is improperly formatted") {
t.Fatalf("err: %v", err)
}
@ -270,8 +270,8 @@ func TestAgent_setupNodeID(t *testing.T) {
if err := ioutil.WriteFile(fileID, []byte("ADF4238a-882b-9ddc-4a9d-5b6758e4159e"), 0600); err != nil {
t.Fatalf("err: %v", err)
}
c.NodeID = ""
if err := a.setupNodeID(c); err != nil {
cfg.NodeID = ""
if err := a.setupNodeID(cfg); err != nil {
t.Fatalf("err: %v", err)
}
if id := a.consulConfig().NodeID; string(id) != "adf4238a-882b-9ddc-4a9d-5b6758e4159e" {
@ -281,9 +281,9 @@ func TestAgent_setupNodeID(t *testing.T) {
func TestAgent_makeNodeID(t *testing.T) {
t.Parallel()
c := TestConfig()
c.NodeID = ""
a := NewTestAgent(t.Name(), c)
cfg := TestConfig()
cfg.NodeID = ""
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
// We should get a valid host-based ID initially.
@ -885,11 +885,11 @@ func TestAgent_ConsulService(t *testing.T) {
func TestAgent_PersistService(t *testing.T) {
t.Parallel()
config := TestConfig()
config.Server = false
config.DataDir = testutil.TempDir(t, "agent") // we manage the data dir
a := NewTestAgent(t.Name(), config)
defer os.RemoveAll(config.DataDir)
cfg := TestConfig()
cfg.Server = false
cfg.DataDir = testutil.TempDir(t, "agent") // we manage the data dir
a := NewTestAgent(t.Name(), cfg)
defer os.RemoveAll(cfg.DataDir)
defer a.Shutdown()
svc := &structs.NodeService{
@ -953,7 +953,7 @@ func TestAgent_PersistService(t *testing.T) {
a.Shutdown()
// Should load it back during later start
agent2, err := NewAgent(config)
agent2, err := NewAgent(cfg)
if err != nil {
t.Fatalf("err: %s", err)
}
@ -1060,9 +1060,9 @@ func TestAgent_PurgeService(t *testing.T) {
func TestAgent_PurgeServiceOnDuplicate(t *testing.T) {
t.Parallel()
config := TestConfig()
config.Server = false
a := NewTestAgent(t.Name(), config)
cfg := TestConfig()
cfg.Server = false
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
svc1 := &structs.NodeService{
@ -1087,8 +1087,8 @@ func TestAgent_PurgeServiceOnDuplicate(t *testing.T) {
Port: 9000,
}
config.Services = []*ServiceDefinition{svc2}
agent2, err := NewAgent(config)
cfg.Services = []*ServiceDefinition{svc2}
agent2, err := NewAgent(cfg)
if err != nil {
t.Fatalf("err: %s", err)
}
@ -1112,15 +1112,15 @@ func TestAgent_PurgeServiceOnDuplicate(t *testing.T) {
func TestAgent_PersistCheck(t *testing.T) {
t.Parallel()
config := TestConfig()
config.Server = false
config.DataDir = testutil.TempDir(t, "agent") // we manage the data dir
a := NewTestAgent(t.Name(), config)
defer os.RemoveAll(config.DataDir)
cfg := TestConfig()
cfg.Server = false
cfg.DataDir = testutil.TempDir(t, "agent") // we manage the data dir
a := NewTestAgent(t.Name(), cfg)
defer os.RemoveAll(cfg.DataDir)
defer a.Shutdown()
check := &structs.HealthCheck{
Node: config.NodeName,
Node: cfg.NodeName,
CheckID: "mem",
Name: "memory check",
Status: api.HealthPassing,
@ -1186,7 +1186,7 @@ func TestAgent_PersistCheck(t *testing.T) {
a.Shutdown()
// Should load it back during later start
agent2, err := NewAgent(config)
agent2, err := NewAgent(cfg)
if err != nil {
t.Fatalf("err: %s", err)
}
@ -1251,15 +1251,15 @@ func TestAgent_PurgeCheck(t *testing.T) {
func TestAgent_PurgeCheckOnDuplicate(t *testing.T) {
t.Parallel()
config := TestConfig()
config.Server = false
config.DataDir = testutil.TempDir(t, "agent") // we manage the data dir
a := NewTestAgent(t.Name(), config)
defer os.RemoveAll(config.DataDir)
cfg := TestConfig()
cfg.Server = false
cfg.DataDir = testutil.TempDir(t, "agent") // we manage the data dir
a := NewTestAgent(t.Name(), cfg)
defer os.RemoveAll(cfg.DataDir)
defer a.Shutdown()
check1 := &structs.HealthCheck{
Node: config.NodeName,
Node: cfg.NodeName,
CheckID: "mem",
Name: "memory check",
Status: api.HealthPassing,
@ -1280,8 +1280,8 @@ func TestAgent_PurgeCheckOnDuplicate(t *testing.T) {
Interval: 30 * time.Second,
}
config.Checks = []*CheckDefinition{check2}
agent2, err := NewAgent(config)
cfg.Checks = []*CheckDefinition{check2}
agent2, err := NewAgent(cfg)
if err != nil {
t.Fatalf("err: %s", err)
}
@ -1298,7 +1298,7 @@ func TestAgent_PurgeCheckOnDuplicate(t *testing.T) {
if !ok {
t.Fatalf("missing check registration")
}
expected := check2.HealthCheck(config.NodeName)
expected := check2.HealthCheck(cfg.NodeName)
if !reflect.DeepEqual(expected, result) {
t.Fatalf("bad: %#v", result)
}
@ -1306,14 +1306,14 @@ func TestAgent_PurgeCheckOnDuplicate(t *testing.T) {
func TestAgent_loadChecks_token(t *testing.T) {
t.Parallel()
config := TestConfig()
config.Checks = append(config.Checks, &CheckDefinition{
cfg := TestConfig()
cfg.Checks = append(cfg.Checks, &CheckDefinition{
ID: "rabbitmq",
Name: "rabbitmq",
Token: "abc123",
TTL: 10 * time.Second,
})
a := NewTestAgent(t.Name(), config)
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
checks := a.state.Checks()
@ -1379,14 +1379,14 @@ func TestAgent_unloadChecks(t *testing.T) {
func TestAgent_loadServices_token(t *testing.T) {
t.Parallel()
config := TestConfig()
config.Services = append(config.Services, &ServiceDefinition{
cfg := TestConfig()
cfg.Services = append(cfg.Services, &ServiceDefinition{
ID: "rabbitmq",
Name: "rabbitmq",
Port: 5672,
Token: "abc123",
})
a := NewTestAgent(t.Name(), config)
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
services := a.state.Services()
@ -1511,10 +1511,10 @@ func TestAgent_Service_MaintenanceMode(t *testing.T) {
func TestAgent_Service_Reap(t *testing.T) {
t.Parallel()
config := TestConfig()
config.CheckReapInterval = time.Millisecond
config.CheckDeregisterIntervalMin = 0
a := NewTestAgent(t.Name(), config)
cfg := TestConfig()
cfg.CheckReapInterval = time.Millisecond
cfg.CheckDeregisterIntervalMin = 0
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
svc := &structs.NodeService{
@ -1585,10 +1585,10 @@ func TestAgent_Service_Reap(t *testing.T) {
func TestAgent_Service_NoReap(t *testing.T) {
t.Parallel()
config := TestConfig()
config.CheckReapInterval = time.Millisecond
config.CheckDeregisterIntervalMin = 0
a := NewTestAgent(t.Name(), config)
cfg := TestConfig()
cfg.CheckReapInterval = time.Millisecond
cfg.CheckDeregisterIntervalMin = 0
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
svc := &structs.NodeService{
@ -1959,9 +1959,9 @@ func TestAgent_purgeCheckState(t *testing.T) {
func TestAgent_GetCoordinate(t *testing.T) {
t.Parallel()
check := func(server bool) {
config := TestConfig()
config.Server = server
a := NewTestAgent(t.Name(), config)
cfg := TestConfig()
cfg.Server = server
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
// This doesn't verify the returned coordinate, but it makes

View File

@ -182,18 +182,18 @@ func TestCatalogNodes_MetaFilter(t *testing.T) {
func TestCatalogNodes_WanTranslation(t *testing.T) {
t.Parallel()
c1 := TestConfig()
c1.Datacenter = "dc1"
c1.TranslateWanAddrs = true
c1.ACLDatacenter = ""
a1 := NewTestAgent(t.Name(), c1)
cfg1 := TestConfig()
cfg1.Datacenter = "dc1"
cfg1.TranslateWanAddrs = true
cfg1.ACLDatacenter = ""
a1 := NewTestAgent(t.Name(), cfg1)
defer a1.Shutdown()
c2 := TestConfig()
c2.Datacenter = "dc2"
c2.TranslateWanAddrs = true
c2.ACLDatacenter = ""
a2 := NewTestAgent(t.Name(), c2)
cfg2 := TestConfig()
cfg2.Datacenter = "dc2"
cfg2.TranslateWanAddrs = true
cfg2.ACLDatacenter = ""
a2 := NewTestAgent(t.Name(), cfg2)
defer a2.Shutdown()
// Wait for the WAN join.
@ -597,18 +597,18 @@ func TestCatalogServiceNodes_NodeMetaFilter(t *testing.T) {
func TestCatalogServiceNodes_WanTranslation(t *testing.T) {
t.Parallel()
c1 := TestConfig()
c1.Datacenter = "dc1"
c1.TranslateWanAddrs = true
c1.ACLDatacenter = ""
a1 := NewTestAgent(t.Name(), c1)
cfg1 := TestConfig()
cfg1.Datacenter = "dc1"
cfg1.TranslateWanAddrs = true
cfg1.ACLDatacenter = ""
a1 := NewTestAgent(t.Name(), cfg1)
defer a1.Shutdown()
c2 := TestConfig()
c2.Datacenter = "dc2"
c2.TranslateWanAddrs = true
c2.ACLDatacenter = ""
a2 := NewTestAgent(t.Name(), c2)
cfg2 := TestConfig()
cfg2.Datacenter = "dc2"
cfg2.TranslateWanAddrs = true
cfg2.ACLDatacenter = ""
a2 := NewTestAgent(t.Name(), cfg2)
defer a2.Shutdown()
// Wait for the WAN join.
@ -804,18 +804,18 @@ func TestCatalogNodeServices(t *testing.T) {
func TestCatalogNodeServices_WanTranslation(t *testing.T) {
t.Parallel()
c1 := TestConfig()
c1.Datacenter = "dc1"
c1.TranslateWanAddrs = true
c1.ACLDatacenter = ""
a1 := NewTestAgent(t.Name(), c1)
cfg1 := TestConfig()
cfg1.Datacenter = "dc1"
cfg1.TranslateWanAddrs = true
cfg1.ACLDatacenter = ""
a1 := NewTestAgent(t.Name(), cfg1)
defer a1.Shutdown()
c2 := TestConfig()
c2.Datacenter = "dc2"
c2.TranslateWanAddrs = true
c2.ACLDatacenter = ""
a2 := NewTestAgent(t.Name(), c2)
cfg2 := TestConfig()
cfg2.Datacenter = "dc2"
cfg2.TranslateWanAddrs = true
cfg2.ACLDatacenter = ""
a2 := NewTestAgent(t.Name(), cfg2)
defer a2.Shutdown()
// Wait for the WAN join.

View File

@ -105,7 +105,7 @@ func TestRetryJoin(t *testing.T) {
a := NewTestAgent(t.Name(), nil)
defer a.Shutdown()
conf2 := TestConfig()
cfg2 := TestConfig()
tmpDir := testutil.TempDir(t, "consul")
defer os.RemoveAll(tmpDir)
@ -137,7 +137,7 @@ func TestRetryJoin(t *testing.T) {
"-server",
"-bind", a.Config.BindAddr,
"-data-dir", tmpDir,
"-node", fmt.Sprintf(`"%s"`, conf2.NodeName),
"-node", fmt.Sprintf(`"%s"`, cfg2.NodeName),
"-advertise", a.Config.BindAddr,
"-retry-join", serfAddr,
"-retry-interval", "1s",
@ -292,7 +292,7 @@ func TestReadCliConfig(t *testing.T) {
func TestRetryJoinFail(t *testing.T) {
t.Parallel()
conf := TestConfig()
cfg := TestConfig()
tmpDir := testutil.TempDir(t, "consul")
defer os.RemoveAll(tmpDir)
@ -304,10 +304,10 @@ func TestRetryJoinFail(t *testing.T) {
Command: baseCommand(new(cli.MockUi)),
}
serfAddr := fmt.Sprintf("%s:%d", conf.BindAddr, conf.Ports.SerfLan)
serfAddr := fmt.Sprintf("%s:%d", cfg.BindAddr, cfg.Ports.SerfLan)
args := []string{
"-bind", conf.BindAddr,
"-bind", cfg.BindAddr,
"-data-dir", tmpDir,
"-retry-join", serfAddr,
"-retry-max", "1",
@ -321,7 +321,7 @@ func TestRetryJoinFail(t *testing.T) {
func TestRetryJoinWanFail(t *testing.T) {
t.Parallel()
conf := TestConfig()
cfg := TestConfig()
tmpDir := testutil.TempDir(t, "consul")
defer os.RemoveAll(tmpDir)
@ -333,11 +333,11 @@ func TestRetryJoinWanFail(t *testing.T) {
Command: baseCommand(new(cli.MockUi)),
}
serfAddr := fmt.Sprintf("%s:%d", conf.BindAddr, conf.Ports.SerfWan)
serfAddr := fmt.Sprintf("%s:%d", cfg.BindAddr, cfg.Ports.SerfWan)
args := []string{
"-server",
"-bind", conf.BindAddr,
"-bind", cfg.BindAddr,
"-data-dir", tmpDir,
"-retry-join-wan", serfAddr,
"-retry-max-wan", "1",

View File

@ -32,8 +32,8 @@ const (
// the provided reply. This is useful for mocking a DNS recursor with
// an expected result.
func makeRecursor(t *testing.T, answer []dns.RR) *dns.Server {
dnsConf := TestConfig()
dnsAddr := fmt.Sprintf("%s:%d", dnsConf.Addresses.DNS, dnsConf.Ports.DNS)
cfg := TestConfig()
dnsAddr := fmt.Sprintf("%s:%d", cfg.Addresses.DNS, cfg.Ports.DNS)
mux := dns.NewServeMux()
mux.HandleFunc(".", func(resp dns.ResponseWriter, msg *dns.Msg) {
ans := &dns.Msg{Answer: answer[:]}
@ -52,8 +52,8 @@ func makeRecursor(t *testing.T, answer []dns.RR) *dns.Server {
}
func makeRecursorWithMessage(t *testing.T, answer dns.Msg) *dns.Server {
dnsConf := TestConfig()
dnsAddr := fmt.Sprintf("%s:%d", dnsConf.Addresses.DNS, dnsConf.Ports.DNS)
cfg := TestConfig()
dnsAddr := fmt.Sprintf("%s:%d", cfg.Addresses.DNS, cfg.Ports.DNS)
mux := dns.NewServeMux()
mux.HandleFunc(".", func(resp dns.ResponseWriter, msg *dns.Msg) {
answer.SetReply(msg)
@ -1211,18 +1211,18 @@ func TestDNS_ServiceLookup_ServiceAddressIPV6(t *testing.T) {
func TestDNS_ServiceLookup_WanAddress(t *testing.T) {
t.Parallel()
c1 := TestConfig()
c1.Datacenter = "dc1"
c1.TranslateWanAddrs = true
c1.ACLDatacenter = ""
a1 := NewTestAgent(t.Name(), c1)
cfg1 := TestConfig()
cfg1.Datacenter = "dc1"
cfg1.TranslateWanAddrs = true
cfg1.ACLDatacenter = ""
a1 := NewTestAgent(t.Name(), cfg1)
defer a1.Shutdown()
c2 := TestConfig()
c2.Datacenter = "dc2"
c2.TranslateWanAddrs = true
c2.ACLDatacenter = ""
a2 := NewTestAgent(t.Name(), c2)
cfg2 := TestConfig()
cfg2.Datacenter = "dc2"
cfg2.TranslateWanAddrs = true
cfg2.ACLDatacenter = ""
a2 := NewTestAgent(t.Name(), cfg2)
defer a2.Shutdown()
// Join WAN cluster
@ -3255,18 +3255,18 @@ func TestDNS_PreparedQuery_TTL(t *testing.T) {
func TestDNS_PreparedQuery_Failover(t *testing.T) {
t.Parallel()
c1 := TestConfig()
c1.Datacenter = "dc1"
c1.TranslateWanAddrs = true
c1.ACLDatacenter = ""
a1 := NewTestAgent(t.Name(), c1)
cfg1 := TestConfig()
cfg1.Datacenter = "dc1"
cfg1.TranslateWanAddrs = true
cfg1.ACLDatacenter = ""
a1 := NewTestAgent(t.Name(), cfg1)
defer a1.Shutdown()
c2 := TestConfig()
c2.Datacenter = "dc2"
c2.TranslateWanAddrs = true
c2.ACLDatacenter = ""
a2 := NewTestAgent(t.Name(), c2)
cfg2 := TestConfig()
cfg2.Datacenter = "dc2"
cfg2.TranslateWanAddrs = true
cfg2.ACLDatacenter = ""
a2 := NewTestAgent(t.Name(), cfg2)
defer a2.Shutdown()
// Join WAN cluster.

View File

@ -54,9 +54,9 @@ func TestEventFire(t *testing.T) {
func TestEventFire_token(t *testing.T) {
t.Parallel()
conf := TestConfig()
conf.ACLDefaultPolicy = "deny"
a := NewTestAgent(t.Name(), conf)
cfg := TestConfig()
cfg.ACLDefaultPolicy = "deny"
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
// Create an ACL token

View File

@ -630,18 +630,18 @@ func TestHealthServiceNodes_PassingFilter(t *testing.T) {
func TestHealthServiceNodes_WanTranslation(t *testing.T) {
t.Parallel()
c1 := TestConfig()
c1.Datacenter = "dc1"
c1.TranslateWanAddrs = true
c1.ACLDatacenter = ""
a1 := NewTestAgent(t.Name(), c1)
cfg1 := TestConfig()
cfg1.Datacenter = "dc1"
cfg1.TranslateWanAddrs = true
cfg1.ACLDatacenter = ""
a1 := NewTestAgent(t.Name(), cfg1)
defer a1.Shutdown()
c2 := TestConfig()
c2.Datacenter = "dc2"
c2.TranslateWanAddrs = true
c2.ACLDatacenter = ""
a2 := NewTestAgent(t.Name(), c2)
cfg2 := TestConfig()
cfg2.Datacenter = "dc2"
cfg2.TranslateWanAddrs = true
cfg2.ACLDatacenter = ""
a2 := NewTestAgent(t.Name(), cfg2)
defer a2.Shutdown()
// Wait for the WAN join.

View File

@ -33,14 +33,14 @@ func TestHTTPServer_UnixSocket(t *testing.T) {
defer os.RemoveAll(tempDir)
socket := filepath.Join(tempDir, "test.sock")
c := TestConfig()
c.Addresses.HTTP = "unix://" + socket
cfg := TestConfig()
cfg.Addresses.HTTP = "unix://" + socket
// Only testing mode, since uid/gid might not be settable
// from test environment.
c.UnixSockets = UnixSocketConfig{}
c.UnixSockets.Perms = "0777"
a := NewTestAgent(t.Name(), c)
cfg.UnixSockets = UnixSocketConfig{}
cfg.UnixSockets.Perms = "0777"
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
// Ensure the socket was created
@ -103,9 +103,9 @@ func TestHTTPServer_UnixSocket_FileExists(t *testing.T) {
t.Fatalf("not a regular file: %s", socket)
}
conf := TestConfig()
conf.Addresses.HTTP = "unix://" + socket
a := NewTestAgent(t.Name(), conf)
cfg := TestConfig()
cfg.Addresses.HTTP = "unix://" + socket
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
// Ensure the file was replaced by the socket
@ -204,9 +204,9 @@ func TestHTTPAPI_TranslateAddrHeader(t *testing.T) {
// Header should be set to true if it's turned on.
{
c := TestConfig()
c.TranslateWanAddrs = true
a := NewTestAgent(t.Name(), c)
cfg := TestConfig()
cfg.TranslateWanAddrs = true
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
resp := httptest.NewRecorder()
@ -226,12 +226,12 @@ func TestHTTPAPI_TranslateAddrHeader(t *testing.T) {
func TestHTTPAPIResponseHeaders(t *testing.T) {
t.Parallel()
c := TestConfig()
c.HTTPAPIResponseHeaders = map[string]string{
cfg := TestConfig()
cfg.HTTPAPIResponseHeaders = map[string]string{
"Access-Control-Allow-Origin": "*",
"X-XSS-Protection": "1; mode=block",
}
a := NewTestAgent(t.Name(), c)
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
resp := httptest.NewRecorder()
@ -519,9 +519,9 @@ func TestACLResolution(t *testing.T) {
func TestEnableWebUI(t *testing.T) {
t.Parallel()
conf := TestConfig()
conf.EnableUI = true
a := NewTestAgent(t.Name(), conf)
cfg := TestConfig()
cfg.EnableUI = true
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
req, _ := http.NewRequest("GET", "/ui/", nil)

View File

@ -53,9 +53,9 @@ func TestAgent_LoadKeyrings(t *testing.T) {
}
// Client should auto-load only the LAN keyring file
conf3 := TestConfig()
conf3.Server = false
a3 := &TestAgent{Name: t.Name(), Config: conf3, Key: key}
cfg3 := TestConfig()
cfg3.Server = false
a3 := &TestAgent{Name: t.Name(), Config: cfg3, Key: key}
a3.Start()
defer a3.Shutdown()
@ -118,11 +118,11 @@ func TestAgentKeyring_ACL(t *testing.T) {
key1 := "tbLJg26ZJyJ9pK3qhc9jig=="
key2 := "4leC33rgtXKIVUr9Nr0snQ=="
conf := TestACLConfig()
conf.ACLDatacenter = "dc1"
conf.ACLMasterToken = "root"
conf.ACLDefaultPolicy = "deny"
a := &TestAgent{Name: t.Name(), Config: conf, Key: key1}
cfg := TestACLConfig()
cfg.ACLDatacenter = "dc1"
cfg.ACLMasterToken = "root"
cfg.ACLDefaultPolicy = "deny"
a := &TestAgent{Name: t.Name(), Config: cfg, Key: key1}
a.Start()
defer a.Shutdown()

View File

@ -463,12 +463,12 @@ service "consul" {
func TestAgentAntiEntropy_Services_ACLDeny(t *testing.T) {
t.Parallel()
conf := TestConfig()
conf.ACLDatacenter = "dc1"
conf.ACLMasterToken = "root"
conf.ACLDefaultPolicy = "deny"
conf.ACLEnforceVersion8 = &BoolTrue
a := NewTestAgent(t.Name(), conf)
cfg := TestConfig()
cfg.ACLDatacenter = "dc1"
cfg.ACLMasterToken = "root"
cfg.ACLDefaultPolicy = "deny"
cfg.ACLEnforceVersion8 = &BoolTrue
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
// Create the ACL
@ -833,12 +833,12 @@ func TestAgentAntiEntropy_Checks(t *testing.T) {
func TestAgentAntiEntropy_Checks_ACLDeny(t *testing.T) {
t.Parallel()
conf := TestConfig()
conf.ACLDatacenter = "dc1"
conf.ACLMasterToken = "root"
conf.ACLDefaultPolicy = "deny"
conf.ACLEnforceVersion8 = &BoolTrue
a := NewTestAgent(t.Name(), conf)
cfg := TestConfig()
cfg.ACLDatacenter = "dc1"
cfg.ACLMasterToken = "root"
cfg.ACLDefaultPolicy = "deny"
cfg.ACLEnforceVersion8 = &BoolTrue
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
// Create the ACL
@ -1069,9 +1069,9 @@ func TestAgentAntiEntropy_Checks_ACLDeny(t *testing.T) {
func TestAgentAntiEntropy_Check_DeferSync(t *testing.T) {
t.Parallel()
conf := TestConfig()
conf.CheckUpdateInterval = 500 * time.Millisecond
a := NewTestAgent(t.Name(), conf)
cfg := TestConfig()
cfg.CheckUpdateInterval = 500 * time.Millisecond
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
// Create a check
@ -1242,10 +1242,10 @@ func TestAgentAntiEntropy_Check_DeferSync(t *testing.T) {
func TestAgentAntiEntropy_NodeInfo(t *testing.T) {
t.Parallel()
conf := TestConfig()
conf.NodeID = types.NodeID("40e4a748-2192-161a-0510-9bf59fe950b5")
conf.Meta["somekey"] = "somevalue"
a := NewTestAgent(t.Name(), conf)
cfg := TestConfig()
cfg.NodeID = types.NodeID("40e4a748-2192-161a-0510-9bf59fe950b5")
cfg.Meta["somekey"] = "somevalue"
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
// Register info
@ -1278,9 +1278,9 @@ func TestAgentAntiEntropy_NodeInfo(t *testing.T) {
id := services.NodeServices.Node.ID
addrs := services.NodeServices.Node.TaggedAddresses
meta := services.NodeServices.Node.Meta
if id != conf.NodeID ||
!reflect.DeepEqual(addrs, conf.TaggedAddresses) ||
!reflect.DeepEqual(meta, conf.Meta) {
if id != cfg.NodeID ||
!reflect.DeepEqual(addrs, cfg.TaggedAddresses) ||
!reflect.DeepEqual(meta, cfg.Meta) {
r.Fatalf("bad: %v", services.NodeServices.Node)
}
})
@ -1301,9 +1301,9 @@ func TestAgentAntiEntropy_NodeInfo(t *testing.T) {
id := services.NodeServices.Node.ID
addrs := services.NodeServices.Node.TaggedAddresses
meta := services.NodeServices.Node.Meta
if id != conf.NodeID ||
!reflect.DeepEqual(addrs, conf.TaggedAddresses) ||
!reflect.DeepEqual(meta, conf.Meta) {
if id != cfg.NodeID ||
!reflect.DeepEqual(addrs, cfg.TaggedAddresses) ||
!reflect.DeepEqual(meta, cfg.Meta) {
r.Fatalf("bad: %v", services.NodeServices.Node)
}
})
@ -1327,10 +1327,10 @@ func TestAgentAntiEntropy_deleteCheck_fails(t *testing.T) {
func TestAgent_serviceTokens(t *testing.T) {
t.Parallel()
config := TestConfig()
config.ACLToken = "default"
cfg := TestConfig()
cfg.ACLToken = "default"
l := new(localState)
l.Init(config, nil)
l.Init(cfg, nil)
l.AddService(&structs.NodeService{
ID: "redis",
@ -1356,10 +1356,10 @@ func TestAgent_serviceTokens(t *testing.T) {
func TestAgent_checkTokens(t *testing.T) {
t.Parallel()
config := TestConfig()
config.ACLToken = "default"
cfg := TestConfig()
cfg.ACLToken = "default"
l := new(localState)
l.Init(config, nil)
l.Init(cfg, nil)
// Returns default when no token is set
if token := l.CheckToken("mem"); token != "default" {
@ -1381,9 +1381,9 @@ func TestAgent_checkTokens(t *testing.T) {
func TestAgent_checkCriticalTime(t *testing.T) {
t.Parallel()
config := TestConfig()
cfg := TestConfig()
l := new(localState)
l.Init(config, nil)
l.Init(cfg, nil)
// Add a passing check and make sure it's not critical.
checkID := types.CheckID("redis:1")
@ -1474,13 +1474,13 @@ func TestAgent_nestedPauseResume(t *testing.T) {
func TestAgent_sendCoordinate(t *testing.T) {
t.Parallel()
conf := TestConfig()
conf.SyncCoordinateRateTarget = 10.0 // updates/sec
conf.SyncCoordinateIntervalMin = 1 * time.Millisecond
conf.ConsulConfig.CoordinateUpdatePeriod = 100 * time.Millisecond
conf.ConsulConfig.CoordinateUpdateBatchSize = 10
conf.ConsulConfig.CoordinateUpdateMaxBatches = 1
a := NewTestAgent(t.Name(), conf)
cfg := TestConfig()
cfg.SyncCoordinateRateTarget = 10.0 // updates/sec
cfg.SyncCoordinateIntervalMin = 1 * time.Millisecond
cfg.ConsulConfig.CoordinateUpdatePeriod = 100 * time.Millisecond
cfg.ConsulConfig.CoordinateUpdateBatchSize = 10
cfg.ConsulConfig.CoordinateUpdateMaxBatches = 1
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
// Make sure the coordinate is present.

View File

@ -79,9 +79,9 @@ func TestOperator_KeyringInstall(t *testing.T) {
t.Parallel()
oldKey := "H3/9gBxcKKRf45CaI2DlRg=="
newKey := "z90lFx3sZZLtTOkutXcwYg=="
config := TestConfig()
config.EncryptKey = oldKey
a := NewTestAgent(t.Name(), config)
cfg := TestConfig()
cfg.EncryptKey = oldKey
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
body := bytes.NewBufferString(fmt.Sprintf("{\"Key\":\"%s\"}", newKey))
@ -114,9 +114,9 @@ func TestOperator_KeyringInstall(t *testing.T) {
func TestOperator_KeyringList(t *testing.T) {
t.Parallel()
key := "H3/9gBxcKKRf45CaI2DlRg=="
config := TestConfig()
config.EncryptKey = key
a := NewTestAgent(t.Name(), config)
cfg := TestConfig()
cfg.EncryptKey = key
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
req, _ := http.NewRequest("GET", "/v1/operator/keyring", nil)
@ -163,9 +163,9 @@ func TestOperator_KeyringRemove(t *testing.T) {
t.Parallel()
key := "H3/9gBxcKKRf45CaI2DlRg=="
tempKey := "z90lFx3sZZLtTOkutXcwYg=="
config := TestConfig()
config.EncryptKey = key
a := NewTestAgent(t.Name(), config)
cfg := TestConfig()
cfg.EncryptKey = key
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
_, err := a.InstallKey(tempKey, "", 0)
@ -221,9 +221,9 @@ func TestOperator_KeyringUse(t *testing.T) {
t.Parallel()
oldKey := "H3/9gBxcKKRf45CaI2DlRg=="
newKey := "z90lFx3sZZLtTOkutXcwYg=="
config := TestConfig()
config.EncryptKey = oldKey
a := NewTestAgent(t.Name(), config)
cfg := TestConfig()
cfg.EncryptKey = oldKey
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
if _, err := a.InstallKey(newKey, "", 0); err != nil {
@ -264,9 +264,9 @@ func TestOperator_KeyringUse(t *testing.T) {
func TestOperator_Keyring_InvalidRelayFactor(t *testing.T) {
t.Parallel()
key := "H3/9gBxcKKRf45CaI2DlRg=="
config := TestConfig()
config.EncryptKey = key
a := NewTestAgent(t.Name(), config)
cfg := TestConfig()
cfg.EncryptKey = key
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
cases := map[string]string{
@ -408,9 +408,9 @@ func TestOperator_AutopilotCASConfiguration(t *testing.T) {
func TestOperator_ServerHealth(t *testing.T) {
t.Parallel()
config := TestConfig()
config.RaftProtocol = 3
a := NewTestAgent(t.Name(), config)
cfg := TestConfig()
cfg.RaftProtocol = 3
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
body := bytes.NewBuffer(nil)
@ -440,11 +440,11 @@ func TestOperator_ServerHealth(t *testing.T) {
func TestOperator_ServerHealth_Unhealthy(t *testing.T) {
t.Parallel()
config := TestConfig()
config.RaftProtocol = 3
cfg := TestConfig()
cfg.RaftProtocol = 3
threshold := time.Duration(-1)
config.Autopilot.LastContactThreshold = &threshold
a := NewTestAgent(t.Name(), config)
cfg.Autopilot.LastContactThreshold = &threshold
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
body := bytes.NewBuffer(nil)

View File

@ -358,10 +358,10 @@ func TestPreparedQuery_Execute(t *testing.T) {
// Ensure WAN translation occurs for a response outside of the local DC.
t.Run("", func(t *testing.T) {
config := TestConfig()
config.Datacenter = "dc1"
config.TranslateWanAddrs = true
a := NewTestAgent(t.Name(), config)
cfg := TestConfig()
cfg.Datacenter = "dc1"
cfg.TranslateWanAddrs = true
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
m := MockPreparedQuery{}
@ -408,10 +408,10 @@ func TestPreparedQuery_Execute(t *testing.T) {
// Ensure WAN translation doesn't occur for the local DC.
t.Run("", func(t *testing.T) {
config := TestConfig()
config.Datacenter = "dc1"
config.TranslateWanAddrs = true
a := NewTestAgent(t.Name(), config)
cfg := TestConfig()
cfg.Datacenter = "dc1"
cfg.TranslateWanAddrs = true
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
m := MockPreparedQuery{}

View File

@ -95,17 +95,16 @@ func TestRexecWriter(t *testing.T) {
func TestRemoteExecGetSpec(t *testing.T) {
t.Parallel()
config := TestConfig()
testRemoteExecGetSpec(t, config)
testRemoteExecGetSpec(t, nil)
}
func TestRemoteExecGetSpec_ACLToken(t *testing.T) {
t.Parallel()
config := TestConfig()
config.ACLDatacenter = "dc1"
config.ACLToken = "root"
config.ACLDefaultPolicy = "deny"
testRemoteExecGetSpec(t, config)
cfg := TestConfig()
cfg.ACLDatacenter = "dc1"
cfg.ACLToken = "root"
cfg.ACLDefaultPolicy = "deny"
testRemoteExecGetSpec(t, cfg)
}
func testRemoteExecGetSpec(t *testing.T, c *Config) {
@ -141,17 +140,16 @@ func testRemoteExecGetSpec(t *testing.T, c *Config) {
func TestRemoteExecWrites(t *testing.T) {
t.Parallel()
config := TestConfig()
testRemoteExecWrites(t, config)
testRemoteExecWrites(t, nil)
}
func TestRemoteExecWrites_ACLToken(t *testing.T) {
t.Parallel()
config := TestConfig()
config.ACLDatacenter = "dc1"
config.ACLToken = "root"
config.ACLDefaultPolicy = "deny"
testRemoteExecWrites(t, config)
cfg := TestConfig()
cfg.ACLDatacenter = "dc1"
cfg.ACLToken = "root"
cfg.ACLDefaultPolicy = "deny"
testRemoteExecWrites(t, cfg)
}
func testRemoteExecWrites(t *testing.T, c *Config) {

View File

@ -210,10 +210,10 @@ func TestSessionDestroy(t *testing.T) {
func TestSessionCustomTTL(t *testing.T) {
t.Parallel()
ttl := 250 * time.Millisecond
config := TestConfig()
config.SessionTTLMin = ttl
config.SessionTTLMinRaw = ttl.String()
a := NewTestAgent(t.Name(), config)
cfg := TestConfig()
cfg.SessionTTLMin = ttl
cfg.SessionTTLMinRaw = ttl.String()
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
id := makeTestSessionTTL(t, a.srv, ttl.String())
@ -252,10 +252,10 @@ func TestSessionCustomTTL(t *testing.T) {
func TestSessionTTLRenew(t *testing.T) {
t.Parallel()
ttl := 250 * time.Millisecond
config := TestConfig()
config.SessionTTLMin = ttl
config.SessionTTLMinRaw = ttl.String()
a := NewTestAgent(t.Name(), config)
cfg := TestConfig()
cfg.SessionTTLMin = ttl
cfg.SessionTTLMinRaw = ttl.String()
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
id := makeTestSessionTTL(t, a.srv, ttl.String())

View File

@ -225,54 +225,54 @@ func TestConfig() *Config {
panic(err)
}
conf := DefaultConfig()
pickRandomPorts(conf)
cfg := DefaultConfig()
pickRandomPorts(cfg)
conf.Version = version.Version
conf.VersionPrerelease = "c.d"
cfg.Version = version.Version
cfg.VersionPrerelease = "c.d"
conf.NodeID = types.NodeID(nodeID)
conf.NodeName = "Node " + nodeID
conf.BindAddr = "127.0.0.1"
conf.AdvertiseAddr = "127.0.0.1"
conf.Datacenter = "dc1"
conf.Bootstrap = true
conf.Server = true
conf.ACLEnforceVersion8 = &BoolFalse
conf.ACLDatacenter = conf.Datacenter
conf.ACLMasterToken = "root"
cfg.NodeID = types.NodeID(nodeID)
cfg.NodeName = "Node " + nodeID
cfg.BindAddr = "127.0.0.1"
cfg.AdvertiseAddr = "127.0.0.1"
cfg.Datacenter = "dc1"
cfg.Bootstrap = true
cfg.Server = true
cfg.ACLEnforceVersion8 = &BoolFalse
cfg.ACLDatacenter = cfg.Datacenter
cfg.ACLMasterToken = "root"
cons := consul.DefaultConfig()
conf.ConsulConfig = cons
ccfg := consul.DefaultConfig()
cfg.ConsulConfig = ccfg
cons.SerfLANConfig.MemberlistConfig.SuspicionMult = 3
cons.SerfLANConfig.MemberlistConfig.ProbeTimeout = 100 * time.Millisecond
cons.SerfLANConfig.MemberlistConfig.ProbeInterval = 100 * time.Millisecond
cons.SerfLANConfig.MemberlistConfig.GossipInterval = 100 * time.Millisecond
ccfg.SerfLANConfig.MemberlistConfig.SuspicionMult = 3
ccfg.SerfLANConfig.MemberlistConfig.ProbeTimeout = 100 * time.Millisecond
ccfg.SerfLANConfig.MemberlistConfig.ProbeInterval = 100 * time.Millisecond
ccfg.SerfLANConfig.MemberlistConfig.GossipInterval = 100 * time.Millisecond
cons.SerfWANConfig.MemberlistConfig.SuspicionMult = 3
cons.SerfWANConfig.MemberlistConfig.ProbeTimeout = 100 * time.Millisecond
cons.SerfWANConfig.MemberlistConfig.ProbeInterval = 100 * time.Millisecond
cons.SerfWANConfig.MemberlistConfig.GossipInterval = 100 * time.Millisecond
ccfg.SerfWANConfig.MemberlistConfig.SuspicionMult = 3
ccfg.SerfWANConfig.MemberlistConfig.ProbeTimeout = 100 * time.Millisecond
ccfg.SerfWANConfig.MemberlistConfig.ProbeInterval = 100 * time.Millisecond
ccfg.SerfWANConfig.MemberlistConfig.GossipInterval = 100 * time.Millisecond
cons.RaftConfig.LeaderLeaseTimeout = 20 * time.Millisecond
cons.RaftConfig.HeartbeatTimeout = 40 * time.Millisecond
cons.RaftConfig.ElectionTimeout = 40 * time.Millisecond
ccfg.RaftConfig.LeaderLeaseTimeout = 20 * time.Millisecond
ccfg.RaftConfig.HeartbeatTimeout = 40 * time.Millisecond
ccfg.RaftConfig.ElectionTimeout = 40 * time.Millisecond
cons.CoordinateUpdatePeriod = 100 * time.Millisecond
cons.ServerHealthInterval = 10 * time.Millisecond
return conf
ccfg.CoordinateUpdatePeriod = 100 * time.Millisecond
ccfg.ServerHealthInterval = 10 * time.Millisecond
return cfg
}
// TestACLConfig returns a default configuration for testing an agent
// with ACLs.
func TestACLConfig() *Config {
c := TestConfig()
c.ACLDatacenter = c.Datacenter
c.ACLDefaultPolicy = "deny"
c.ACLMasterToken = "root"
c.ACLAgentToken = "root"
c.ACLAgentMasterToken = "towel"
c.ACLEnforceVersion8 = &BoolTrue
return c
cfg := TestConfig()
cfg.ACLDatacenter = cfg.Datacenter
cfg.ACLDefaultPolicy = "deny"
cfg.ACLMasterToken = "root"
cfg.ACLAgentToken = "root"
cfg.ACLAgentMasterToken = "towel"
cfg.ACLEnforceVersion8 = &BoolTrue
return cfg
}

View File

@ -25,9 +25,9 @@ func TestUiIndex(t *testing.T) {
defer os.RemoveAll(uiDir)
// Make the server
c := TestConfig()
c.UIDir = uiDir
a := NewTestAgent(t.Name(), c)
cfg := TestConfig()
cfg.UIDir = uiDir
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
// Create file

View File

@ -183,9 +183,9 @@ func TestFireReceiveEvent(t *testing.T) {
func TestUserEventToken(t *testing.T) {
t.Parallel()
conf := TestConfig()
conf.ACLDefaultPolicy = "deny" // Set the default policies to deny
a := NewTestAgent(t.Name(), conf)
cfg := TestConfig()
cfg.ACLDefaultPolicy = "deny" // Set the default policies to deny
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
// Create an ACL token

View File

@ -28,8 +28,8 @@ func TestExecCommand_implements(t *testing.T) {
}
func TestExecCommandRun(t *testing.T) {
a1 := testAgentWithConfig(t, func(c *agent.Config) {
c.DisableRemoteExec = agent.Bool(false)
a1 := testAgentWithConfig(t, func(cfg *agent.Config) {
cfg.DisableRemoteExec = agent.Bool(false)
})
defer a1.Shutdown()
waitForLeader(t, a1.httpAddr)
@ -48,14 +48,14 @@ func TestExecCommandRun(t *testing.T) {
}
func TestExecCommandRun_CrossDC(t *testing.T) {
a1 := testAgentWithConfig(t, func(c *agent.Config) {
c.DisableRemoteExec = agent.Bool(false)
a1 := testAgentWithConfig(t, func(cfg *agent.Config) {
cfg.DisableRemoteExec = agent.Bool(false)
})
defer a1.Shutdown()
a2 := testAgentWithConfig(t, func(c *agent.Config) {
c.Datacenter = "dc2"
c.DisableRemoteExec = agent.Bool(false)
a2 := testAgentWithConfig(t, func(cfg *agent.Config) {
cfg.Datacenter = "dc2"
cfg.DisableRemoteExec = agent.Bool(false)
})
defer a2.Shutdown()
@ -143,8 +143,8 @@ func TestExecCommand_Validate(t *testing.T) {
}
func TestExecCommand_Sessions(t *testing.T) {
a1 := testAgentWithConfig(t, func(c *agent.Config) {
c.DisableRemoteExec = agent.Bool(false)
a1 := testAgentWithConfig(t, func(cfg *agent.Config) {
cfg.DisableRemoteExec = agent.Bool(false)
})
defer a1.Shutdown()
waitForLeader(t, a1.httpAddr)
@ -186,8 +186,8 @@ func TestExecCommand_Sessions(t *testing.T) {
}
func TestExecCommand_Sessions_Foreign(t *testing.T) {
a1 := testAgentWithConfig(t, func(c *agent.Config) {
c.DisableRemoteExec = agent.Bool(false)
a1 := testAgentWithConfig(t, func(cfg *agent.Config) {
cfg.DisableRemoteExec = agent.Bool(false)
})
defer a1.Shutdown()
waitForLeader(t, a1.httpAddr)
@ -239,8 +239,8 @@ func TestExecCommand_Sessions_Foreign(t *testing.T) {
}
func TestExecCommand_UploadDestroy(t *testing.T) {
a1 := testAgentWithConfig(t, func(c *agent.Config) {
c.DisableRemoteExec = agent.Bool(false)
a1 := testAgentWithConfig(t, func(cfg *agent.Config) {
cfg.DisableRemoteExec = agent.Bool(false)
})
defer a1.Shutdown()
waitForLeader(t, a1.httpAddr)
@ -298,8 +298,8 @@ func TestExecCommand_UploadDestroy(t *testing.T) {
}
func TestExecCommand_StreamResults(t *testing.T) {
a1 := testAgentWithConfig(t, func(c *agent.Config) {
c.DisableRemoteExec = agent.Bool(false)
a1 := testAgentWithConfig(t, func(cfg *agent.Config) {
cfg.DisableRemoteExec = agent.Bool(false)
})
defer a1.Shutdown()
waitForLeader(t, a1.httpAddr)

View File

@ -28,8 +28,8 @@ func TestKeyringCommandRun(t *testing.T) {
key2 := "kZyFABeAmc64UMTrm9XuKA=="
// Begin with a single key
a1 := testAgentWithConfig(t, func(c *agent.Config) {
c.EncryptKey = key1
a1 := testAgentWithConfig(t, func(cfg *agent.Config) {
cfg.EncryptKey = key1
})
defer a1.Shutdown()

View File

@ -54,8 +54,8 @@ func TestRTTCommand_Run_BadArgs(t *testing.T) {
func TestRTTCommand_Run_LAN(t *testing.T) {
updatePeriod := 10 * time.Millisecond
a := testAgentWithConfig(t, func(c *agent.Config) {
c.ConsulConfig.CoordinateUpdatePeriod = updatePeriod
a := testAgentWithConfig(t, func(cfg *agent.Config) {
cfg.ConsulConfig.CoordinateUpdatePeriod = updatePeriod
})
defer a.Shutdown()
waitForLeader(t, a.httpAddr)

View File

@ -44,7 +44,7 @@ func testAgent(t *testing.T) *server {
}
func testAgentWithAPIClient(t *testing.T) (*server, *api.Client) {
agent := testAgentWithConfig(t, func(c *agent.Config) {})
agent := testAgentWithConfig(t, func(cfg *agent.Config) {})
client, err := api.NewClient(&api.Config{Address: agent.httpAddr})
if err != nil {
t.Fatalf("consul client: %#v", err)
@ -52,7 +52,7 @@ func testAgentWithAPIClient(t *testing.T) (*server, *api.Client) {
return agent, client
}
func testAgentWithConfig(t *testing.T, cb func(c *agent.Config)) *server {
func testAgentWithConfig(t *testing.T, cb func(cfg *agent.Config)) *server {
conf := nextConfig()
if cb != nil {
cb(conf)