2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2021-10-01 13:59:55 +00:00
|
|
|
//go:build !ent
|
2021-04-19 17:29:36 +00:00
|
|
|
// +build !ent
|
|
|
|
|
|
|
|
package structs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-03-15 12:42:43 +00:00
|
|
|
"github.com/hashicorp/nomad/ci"
|
2021-04-19 17:29:36 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestJob_ConfigEntries(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-19 17:29:36 +00:00
|
|
|
|
|
|
|
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
|
2021-10-01 13:59:55 +00:00
|
|
|
"": {
|
2021-04-19 17:29:36 +00:00
|
|
|
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)
|
|
|
|
}
|