2021-09-16 06:13:09 +00:00
|
|
|
package taskenv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_InterpolateNetworks(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
inputTaskEnv *TaskEnv
|
|
|
|
inputNetworks structs.Networks
|
|
|
|
expectedOutputNetworks structs.Networks
|
|
|
|
name string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
inputTaskEnv: testEnv,
|
|
|
|
inputNetworks: structs.Networks{
|
|
|
|
{Hostname: "my-little-pony"},
|
|
|
|
},
|
|
|
|
expectedOutputNetworks: structs.Networks{
|
|
|
|
{Hostname: "my-little-pony"},
|
|
|
|
},
|
|
|
|
name: "non-interpolated hostname",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
inputTaskEnv: testEnv,
|
|
|
|
inputNetworks: structs.Networks{
|
|
|
|
{Hostname: "${foo}-cache-${baz}"},
|
|
|
|
},
|
|
|
|
expectedOutputNetworks: structs.Networks{
|
|
|
|
{Hostname: "bar-cache-blah"},
|
|
|
|
},
|
|
|
|
name: "interpolated hostname",
|
|
|
|
},
|
2022-02-16 13:39:44 +00:00
|
|
|
{
|
|
|
|
inputTaskEnv: testEnv,
|
|
|
|
inputNetworks: structs.Networks{
|
|
|
|
{
|
|
|
|
DNS: &structs.DNSConfig{
|
|
|
|
Servers: []string{"127.0.0.1"},
|
|
|
|
Options: []string{"some-opt"},
|
|
|
|
Searches: []string{"example.com"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectedOutputNetworks: structs.Networks{
|
|
|
|
{
|
|
|
|
DNS: &structs.DNSConfig{
|
|
|
|
Servers: []string{"127.0.0.1"},
|
|
|
|
Options: []string{"some-opt"},
|
|
|
|
Searches: []string{"example.com"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
name: "non-interpolated dns servers",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
inputTaskEnv: testEnv,
|
|
|
|
inputNetworks: structs.Networks{
|
|
|
|
{
|
|
|
|
DNS: &structs.DNSConfig{
|
|
|
|
Servers: []string{"${foo}"},
|
|
|
|
Options: []string{"${foo}-opt"},
|
|
|
|
Searches: []string{"${foo}.example.com"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectedOutputNetworks: structs.Networks{
|
|
|
|
{
|
|
|
|
DNS: &structs.DNSConfig{
|
|
|
|
Servers: []string{"bar"},
|
|
|
|
Options: []string{"bar-opt"},
|
|
|
|
Searches: []string{"bar.example.com"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
name: "interpolated dns servers",
|
|
|
|
},
|
2021-09-16 06:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
actualOutput := InterpolateNetworks(tc.inputTaskEnv, tc.inputNetworks)
|
|
|
|
assert.Equal(t, tc.expectedOutputNetworks, actualOutput, tc.name)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|