mirror of https://github.com/status-im/consul.git
make tests use a dummy node_name to avoid environment related failures (#10262)
* fix tests to use a dummy nodeName and not fail when hostname is not a valid nodeName * remove conditional testing * add test when node name is invalid
This commit is contained in:
parent
d3ca202a32
commit
15dddc9edb
|
@ -6688,7 +6688,7 @@ func TestDNS_trimUDPResponse_NoTrim(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
cfg := loadRuntimeConfig(t, `node_name = "test" data_dir = "a" bind_addr = "127.0.0.1"`)
|
||||
cfg := loadRuntimeConfig(t, `node_name = "test" data_dir = "a" bind_addr = "127.0.0.1" node_name = "dummy"`)
|
||||
if trimmed := trimUDPResponse(req, resp, cfg.DNSUDPAnswerLimit); trimmed {
|
||||
t.Fatalf("Bad %#v", *resp)
|
||||
}
|
||||
|
@ -6722,7 +6722,7 @@ func TestDNS_trimUDPResponse_NoTrim(t *testing.T) {
|
|||
|
||||
func TestDNS_trimUDPResponse_TrimLimit(t *testing.T) {
|
||||
t.Parallel()
|
||||
cfg := loadRuntimeConfig(t, `node_name = "test" data_dir = "a" bind_addr = "127.0.0.1"`)
|
||||
cfg := loadRuntimeConfig(t, `node_name = "test" data_dir = "a" bind_addr = "127.0.0.1" node_name = "dummy"`)
|
||||
|
||||
req, resp, expected := &dns.Msg{}, &dns.Msg{}, &dns.Msg{}
|
||||
for i := 0; i < cfg.DNSUDPAnswerLimit+1; i++ {
|
||||
|
@ -6770,7 +6770,7 @@ func loadRuntimeConfig(t *testing.T, hcl string) *config.RuntimeConfig {
|
|||
|
||||
func TestDNS_trimUDPResponse_TrimSize(t *testing.T) {
|
||||
t.Parallel()
|
||||
cfg := loadRuntimeConfig(t, `node_name = "test" data_dir = "a" bind_addr = "127.0.0.1"`)
|
||||
cfg := loadRuntimeConfig(t, `node_name = "test" data_dir = "a" bind_addr = "127.0.0.1" node_name = "dummy"`)
|
||||
|
||||
req, resp := &dns.Msg{}, &dns.Msg{}
|
||||
for i := 0; i < 100; i++ {
|
||||
|
@ -6823,7 +6823,7 @@ func TestDNS_trimUDPResponse_TrimSize(t *testing.T) {
|
|||
|
||||
func TestDNS_trimUDPResponse_TrimSizeEDNS(t *testing.T) {
|
||||
t.Parallel()
|
||||
cfg := loadRuntimeConfig(t, `node_name = "test" data_dir = "a" bind_addr = "127.0.0.1"`)
|
||||
cfg := loadRuntimeConfig(t, `node_name = "test" data_dir = "a" bind_addr = "127.0.0.1" node_name = "dummy"`)
|
||||
|
||||
req, resp := &dns.Msg{}, &dns.Msg{}
|
||||
|
||||
|
@ -7126,7 +7126,7 @@ func TestDNS_syncExtra(t *testing.T) {
|
|||
|
||||
func TestDNS_Compression_trimUDPResponse(t *testing.T) {
|
||||
t.Parallel()
|
||||
cfg := loadRuntimeConfig(t, `data_dir = "a" bind_addr = "127.0.0.1"`)
|
||||
cfg := loadRuntimeConfig(t, `data_dir = "a" bind_addr = "127.0.0.1" node_name = "dummy"`)
|
||||
|
||||
req, m := dns.Msg{}, dns.Msg{}
|
||||
trimUDPResponse(&req, &m, cfg.DNSUDPAnswerLimit)
|
||||
|
|
|
@ -1770,7 +1770,7 @@ func TestAgentAntiEntropy_NodeInfo(t *testing.T) {
|
|||
|
||||
func TestState_ServiceTokens(t *testing.T) {
|
||||
tokens := new(token.Store)
|
||||
cfg := loadRuntimeConfig(t, `bind_addr = "127.0.0.1" data_dir = "dummy"`)
|
||||
cfg := loadRuntimeConfig(t, `bind_addr = "127.0.0.1" data_dir = "dummy" node_name = "dummy"`)
|
||||
l := local.NewState(agent.LocalConfig(cfg), nil, tokens)
|
||||
l.TriggerSyncChanges = func() {}
|
||||
|
||||
|
@ -1812,7 +1812,7 @@ func loadRuntimeConfig(t *testing.T, hcl string) *config.RuntimeConfig {
|
|||
|
||||
func TestState_CheckTokens(t *testing.T) {
|
||||
tokens := new(token.Store)
|
||||
cfg := loadRuntimeConfig(t, `bind_addr = "127.0.0.1" data_dir = "dummy"`)
|
||||
cfg := loadRuntimeConfig(t, `bind_addr = "127.0.0.1" data_dir = "dummy" node_name = "dummy"`)
|
||||
l := local.NewState(agent.LocalConfig(cfg), nil, tokens)
|
||||
l.TriggerSyncChanges = func() {}
|
||||
|
||||
|
@ -1846,7 +1846,7 @@ func TestState_CheckTokens(t *testing.T) {
|
|||
|
||||
func TestAgent_CheckCriticalTime(t *testing.T) {
|
||||
t.Parallel()
|
||||
cfg := loadRuntimeConfig(t, `bind_addr = "127.0.0.1" data_dir = "dummy"`)
|
||||
cfg := loadRuntimeConfig(t, `bind_addr = "127.0.0.1" data_dir = "dummy" node_name = "dummy"`)
|
||||
l := local.NewState(agent.LocalConfig(cfg), nil, new(token.Store))
|
||||
l.TriggerSyncChanges = func() {}
|
||||
|
||||
|
@ -1910,7 +1910,7 @@ func TestAgent_CheckCriticalTime(t *testing.T) {
|
|||
|
||||
func TestAgent_AddCheckFailure(t *testing.T) {
|
||||
t.Parallel()
|
||||
cfg := loadRuntimeConfig(t, `bind_addr = "127.0.0.1" data_dir = "dummy"`)
|
||||
cfg := loadRuntimeConfig(t, `bind_addr = "127.0.0.1" data_dir = "dummy" node_name = "dummy"`)
|
||||
l := local.NewState(agent.LocalConfig(cfg), nil, new(token.Store))
|
||||
l.TriggerSyncChanges = func() {}
|
||||
|
||||
|
@ -1933,7 +1933,7 @@ func TestAgent_AliasCheck(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
require := require.New(t)
|
||||
cfg := loadRuntimeConfig(t, `bind_addr = "127.0.0.1" data_dir = "dummy"`)
|
||||
cfg := loadRuntimeConfig(t, `bind_addr = "127.0.0.1" data_dir = "dummy" node_name = "dummy"`)
|
||||
l := local.NewState(agent.LocalConfig(cfg), nil, new(token.Store))
|
||||
l.TriggerSyncChanges = func() {}
|
||||
|
||||
|
@ -1984,7 +1984,7 @@ func TestAgent_AliasCheck_ServiceNotification(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
require := require.New(t)
|
||||
cfg := loadRuntimeConfig(t, `bind_addr = "127.0.0.1" data_dir = "dummy"`)
|
||||
cfg := loadRuntimeConfig(t, `bind_addr = "127.0.0.1" data_dir = "dummy" node_name = "dummy"`)
|
||||
l := local.NewState(agent.LocalConfig(cfg), nil, new(token.Store))
|
||||
l.TriggerSyncChanges = func() {}
|
||||
|
||||
|
|
|
@ -16,12 +16,28 @@ import (
|
|||
// tests if that ever changes.
|
||||
func TestDevModeHasNoServices(t *testing.T) {
|
||||
devMode := true
|
||||
result, err := config.Load(config.LoadOpts{DevMode: &devMode})
|
||||
opts := config.LoadOpts{
|
||||
DevMode: &devMode,
|
||||
HCL: []string{`node_name = "dummy"`},
|
||||
}
|
||||
result, err := config.Load(opts)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, result.Warnings, 0)
|
||||
require.Len(t, result.RuntimeConfig.Services, 0)
|
||||
}
|
||||
|
||||
func TestInvalidNodeNameWarning(t *testing.T) {
|
||||
devMode := true
|
||||
opts := config.LoadOpts{
|
||||
DevMode: &devMode,
|
||||
HCL: []string{`node_name = "dummy.local"`},
|
||||
}
|
||||
result, err := config.Load(opts)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, result.Warnings, 1)
|
||||
require.Contains(t, result.Warnings[0], "will not be discoverable via DNS due to invalid characters. Valid characters include all alpha-numerics and dashes.")
|
||||
}
|
||||
|
||||
func TestStructsToAgentService(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
@ -160,10 +176,10 @@ func TestStructsToAgentService(t *testing.T) {
|
|||
tc := tt
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
r := require.New(t)
|
||||
actual, err := serviceToAgentService(tc.Input)
|
||||
require.NoError(err)
|
||||
require.Equal(tc.Output, actual)
|
||||
r.NoError(err)
|
||||
r.Equal(tc.Output, actual)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue