4caac1a92f
* Add `bridge_network_hairpin_mode` client config setting * Add node attribute: `nomad.bridge.hairpin_mode` * Changed format string to use `%q` to escape user provided data * Add test to validate template JSON for developer safety Co-authored-by: Daniel Bennett <dbennett@hashicorp.com>
49 lines
915 B
Go
49 lines
915 B
Go
package allocrunner
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/nomad/ci"
|
|
"github.com/shoenig/test/must"
|
|
)
|
|
|
|
func Test_buildNomadBridgeNetConfig(t *testing.T) {
|
|
ci.Parallel(t)
|
|
testCases := []struct {
|
|
name string
|
|
b *bridgeNetworkConfigurator
|
|
}{
|
|
{
|
|
name: "empty",
|
|
b: &bridgeNetworkConfigurator{},
|
|
},
|
|
|
|
{
|
|
name: "hairpin",
|
|
b: &bridgeNetworkConfigurator{
|
|
bridgeName: defaultNomadBridgeName,
|
|
allocSubnet: defaultNomadAllocSubnet,
|
|
hairpinMode: true,
|
|
},
|
|
},
|
|
{
|
|
name: "bad_input",
|
|
b: &bridgeNetworkConfigurator{
|
|
bridgeName: `bad"`,
|
|
allocSubnet: defaultNomadAllocSubnet,
|
|
hairpinMode: true,
|
|
},
|
|
},
|
|
}
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
tc := tc
|
|
ci.Parallel(t)
|
|
bCfg := buildNomadBridgeNetConfig(*tc.b)
|
|
// Validate that the JSON created is rational
|
|
must.True(t, json.Valid(bCfg))
|
|
})
|
|
}
|
|
}
|