From 7daa4706a676ffe0df44fe0776a812210c2320eb Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Tue, 11 Oct 2016 13:28:18 -0700 Subject: [PATCH] Tests --- client/client_test.go | 8 ++++++-- client/vaultclient/vaultclient_test.go | 3 ++- nomad/job_endpoint_test.go | 18 +++++++++++------- nomad/node_endpoint_test.go | 5 +++-- nomad/server_test.go | 3 ++- nomad/vault_test.go | 6 ++++-- 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/client/client_test.go b/client/client_test.go index 047170c3a..838016864 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -36,9 +36,11 @@ func getPort() int { } func testServer(t *testing.T, cb func(*nomad.Config)) (*nomad.Server, string) { + f := false + // Setup the default settings config := nomad.DefaultConfig() - config.VaultConfig.Enabled = false + config.VaultConfig.Enabled = &f config.Build = "unittest" config.DevMode = true config.RPCAddr = &net.TCPAddr{ @@ -84,8 +86,10 @@ func testServer(t *testing.T, cb func(*nomad.Config)) (*nomad.Server, string) { } func testClient(t *testing.T, cb func(c *config.Config)) *Client { + f := false + conf := config.DefaultConfig() - conf.VaultConfig.Enabled = false + conf.VaultConfig.Enabled = &f conf.DevMode = true if cb != nil { cb(conf) diff --git a/client/vaultclient/vaultclient_test.go b/client/vaultclient/vaultclient_test.go index e55fd35bf..4adf3d09e 100644 --- a/client/vaultclient/vaultclient_test.go +++ b/client/vaultclient/vaultclient_test.go @@ -90,8 +90,9 @@ func TestVaultClient_TokenRenewals(t *testing.T) { } func TestVaultClient_Heap(t *testing.T) { + tr := true conf := config.DefaultConfig() - conf.VaultConfig.Enabled = true + conf.VaultConfig.Enabled = &tr conf.VaultConfig.Token = "testvaulttoken" conf.VaultConfig.TaskTokenTTL = "10s" diff --git a/nomad/job_endpoint_test.go b/nomad/job_endpoint_test.go index d909032cd..cb575a32d 100644 --- a/nomad/job_endpoint_test.go +++ b/nomad/job_endpoint_test.go @@ -364,7 +364,8 @@ func TestJobEndpoint_Register_EnforceIndex(t *testing.T) { func TestJobEndpoint_Register_Vault_Disabled(t *testing.T) { s1 := testServer(t, func(c *Config) { c.NumSchedulers = 0 // Prevent automatic dequeue - c.VaultConfig.Enabled = false + f := false + c.VaultConfig.Enabled = &f }) defer s1.Shutdown() codec := rpcClient(t, s1) @@ -395,8 +396,9 @@ func TestJobEndpoint_Register_Vault_AllowUnauthenticated(t *testing.T) { testutil.WaitForLeader(t, s1.RPC) // Enable vault and allow authenticated - s1.config.VaultConfig.Enabled = true - s1.config.VaultConfig.AllowUnauthenticated = true + tr := true + s1.config.VaultConfig.Enabled = &tr + s1.config.VaultConfig.AllowUnauthenticated = &tr // Replace the Vault Client on the server s1.vault = &TestVaultClient{} @@ -439,8 +441,9 @@ func TestJobEndpoint_Register_Vault_NoToken(t *testing.T) { testutil.WaitForLeader(t, s1.RPC) // Enable vault - s1.config.VaultConfig.Enabled = true - s1.config.VaultConfig.AllowUnauthenticated = false + tr, f := true, false + s1.config.VaultConfig.Enabled = &tr + s1.config.VaultConfig.AllowUnauthenticated = &f // Replace the Vault Client on the server s1.vault = &TestVaultClient{} @@ -471,8 +474,9 @@ func TestJobEndpoint_Register_Vault_Policies(t *testing.T) { testutil.WaitForLeader(t, s1.RPC) // Enable vault - s1.config.VaultConfig.Enabled = true - s1.config.VaultConfig.AllowUnauthenticated = false + tr, f := true, false + s1.config.VaultConfig.Enabled = &tr + s1.config.VaultConfig.AllowUnauthenticated = &f // Replace the Vault Client on the server tvc := &TestVaultClient{} diff --git a/nomad/node_endpoint_test.go b/nomad/node_endpoint_test.go index 06b2bf82e..bf4c22489 100644 --- a/nomad/node_endpoint_test.go +++ b/nomad/node_endpoint_test.go @@ -1869,8 +1869,9 @@ func TestClientEndpoint_DeriveVaultToken(t *testing.T) { testutil.WaitForLeader(t, s1.RPC) // Enable vault and allow authenticated - s1.config.VaultConfig.Enabled = true - s1.config.VaultConfig.AllowUnauthenticated = true + tr := true + s1.config.VaultConfig.Enabled = &tr + s1.config.VaultConfig.AllowUnauthenticated = &tr // Replace the Vault Client on the server tvc := &TestVaultClient{} diff --git a/nomad/server_test.go b/nomad/server_test.go index b28058bab..c66a22498 100644 --- a/nomad/server_test.go +++ b/nomad/server_test.go @@ -58,7 +58,8 @@ func testServer(t *testing.T, cb func(*Config)) *Server { config.RaftTimeout = 500 * time.Millisecond // Disable Vault - config.VaultConfig.Enabled = false + f := false + config.VaultConfig.Enabled = &f // Invoke the callback if any if cb != nil { diff --git a/nomad/vault_test.go b/nomad/vault_test.go index 2da6ca5c9..41249e2ce 100644 --- a/nomad/vault_test.go +++ b/nomad/vault_test.go @@ -36,7 +36,8 @@ func TestVaultClient_BadConfig(t *testing.T) { t.Fatalf("expected config error: %v", err) } - conf.Enabled = true + tr := true + conf.Enabled = &tr _, err = NewVaultClient(conf, logger, nil) if err == nil || !strings.Contains(err.Error(), "token must be set") { t.Fatalf("Expected token unset error: %v", err) @@ -229,8 +230,9 @@ func parseTTLFromLookup(s *vapi.Secret, t *testing.T) int64 { } func TestVaultClient_LookupToken_Invalid(t *testing.T) { + tr := true conf := &config.VaultConfig{ - Enabled: true, + Enabled: &tr, Addr: "http://foobar:12345", Token: structs.GenerateUUID(), }