Fix VaultPolicies returning non-empty map when there are no policies

This commit is contained in:
Alex Dadgar 2016-09-21 11:14:09 -07:00
parent 50efdb00e9
commit 5a9919bfbf
2 changed files with 5 additions and 2 deletions

View file

@ -1844,7 +1844,7 @@ func TestClientEndpoint_DeriveVaultToken_Bad(t *testing.T) {
// Now we should get an error about the job not needing any Vault secrets
err = msgpackrpc.CallWithCodec(codec, "Node.DeriveVaultToken", req, &resp)
if err == nil || !strings.Contains(err.Error(), "without defined Vault") {
if err == nil || !strings.Contains(err.Error(), "does not require") {
t.Fatalf("Expected no policies error: %v", err)
}

View file

@ -1277,7 +1277,6 @@ func (j *Job) VaultPolicies() map[string]map[string]*Vault {
for _, tg := range j.TaskGroups {
tgPolicies := make(map[string]*Vault, len(tg.Tasks))
policies[tg.Name] = tgPolicies
for _, task := range tg.Tasks {
if task.Vault == nil {
@ -1286,6 +1285,10 @@ func (j *Job) VaultPolicies() map[string]map[string]*Vault {
tgPolicies[task.Name] = task.Vault
}
if len(tgPolicies) != 0 {
policies[tg.Name] = tgPolicies
}
}
return policies