open-nomad/nomad/structs/consul_oss_test.go
Seth Hoenig 509490e5d2 e2e: consul namespace tests from nomad ent
(cherry-picked from ent without _ent things)

This is part 2/4 of e2e tests for Consul Namespaces. Took a
first pass at what the parameterized tests can look like, but
only on the ENT side for this PR. Will continue to refactor
in the next PRs.

Also fixes 2 bugs:
 - Config Entries registered by Nomad Server on job registration
   were not getting Namespace set
 - Group level script checks were not getting Namespace set

Those changes will need to be copied back to Nomad OSS.

Nomad OSS + no ACLs (previously, needs refactor)
Nomad ENT + no ACLs (this)
Nomad OSS + ACLs (todo)
Nomad ENT + ALCs (todo)
2021-04-19 15:35:31 -06:00

94 lines
2 KiB
Go

// +build !ent
package structs
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestJob_ConfigEntries(t *testing.T) {
t.Parallel()
ingress := &ConsulConnect{
Gateway: &ConsulGateway{
Ingress: new(ConsulIngressConfigEntry),
},
}
terminating := &ConsulConnect{
Gateway: &ConsulGateway{
Terminating: new(ConsulTerminatingConfigEntry),
},
}
j := &Job{
TaskGroups: []*TaskGroup{{
Name: "group1",
Consul: nil,
Services: []*Service{{
Name: "group1-service1",
Connect: ingress,
}, {
Name: "group1-service2",
Connect: nil,
}, {
Name: "group1-service3",
Connect: terminating,
}},
}, {
Name: "group2",
Consul: nil,
Services: []*Service{{
Name: "group2-service1",
Connect: ingress,
}},
}, {
Name: "group3",
Consul: &Consul{Namespace: "apple"},
Services: []*Service{{
Name: "group3-service1",
Connect: ingress,
}},
}, {
Name: "group4",
Consul: &Consul{Namespace: "apple"},
Services: []*Service{{
Name: "group4-service1",
Connect: ingress,
}, {
Name: "group4-service2",
Connect: terminating,
}},
}, {
Name: "group5",
Consul: &Consul{Namespace: "banana"},
Services: []*Service{{
Name: "group5-service1",
Connect: ingress,
}},
}},
}
exp := map[string]*ConsulConfigEntries{
// in OSS, consul namespace is not supported
"": &ConsulConfigEntries{
Ingress: map[string]*ConsulIngressConfigEntry{
"group1-service1": new(ConsulIngressConfigEntry),
"group2-service1": new(ConsulIngressConfigEntry),
"group3-service1": new(ConsulIngressConfigEntry),
"group4-service1": new(ConsulIngressConfigEntry),
"group5-service1": new(ConsulIngressConfigEntry),
},
Terminating: map[string]*ConsulTerminatingConfigEntry{
"group1-service3": new(ConsulTerminatingConfigEntry),
"group4-service2": new(ConsulTerminatingConfigEntry),
},
},
}
entries := j.ConfigEntries()
require.EqualValues(t, exp, entries)
}