mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
test: assert service interpolation behavior
Ported from pre-0.9 tests.
This commit is contained in:
86
client/allocrunner/taskrunner/service_hook_test.go
Normal file
86
client/allocrunner/taskrunner/service_hook_test.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package taskrunner
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/nomad/client/taskenv"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TestTaskRunner_ServiceHook_InterpolateServices asserts that all service
|
||||
// and check fields are properly interpolated.
|
||||
func TestTaskRunner_ServiceHook_InterpolateServices(t *testing.T) {
|
||||
t.Parallel()
|
||||
services := []*structs.Service{
|
||||
{
|
||||
Name: "${name}",
|
||||
PortLabel: "${portlabel}",
|
||||
Tags: []string{"${tags}"},
|
||||
Checks: []*structs.ServiceCheck{
|
||||
{
|
||||
Name: "${checkname}",
|
||||
Type: "${checktype}",
|
||||
Command: "${checkcmd}",
|
||||
Args: []string{"${checkarg}"},
|
||||
Path: "${checkstr}",
|
||||
Protocol: "${checkproto}",
|
||||
PortLabel: "${checklabel}",
|
||||
InitialStatus: "${checkstatus}",
|
||||
Method: "${checkmethod}",
|
||||
Header: map[string][]string{
|
||||
"${checkheaderk}": {"${checkheaderv}"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
env := &taskenv.TaskEnv{
|
||||
EnvMap: map[string]string{
|
||||
"name": "name",
|
||||
"portlabel": "portlabel",
|
||||
"tags": "tags",
|
||||
"checkname": "checkname",
|
||||
"checktype": "checktype",
|
||||
"checkcmd": "checkcmd",
|
||||
"checkarg": "checkarg",
|
||||
"checkstr": "checkstr",
|
||||
"checkpath": "checkpath",
|
||||
"checkproto": "checkproto",
|
||||
"checklabel": "checklabel",
|
||||
"checkstatus": "checkstatus",
|
||||
"checkmethod": "checkmethod",
|
||||
"checkheaderk": "checkheaderk",
|
||||
"checkheaderv": "checkheaderv",
|
||||
},
|
||||
}
|
||||
|
||||
interpolated := interpolateServices(env, services)
|
||||
|
||||
exp := []*structs.Service{
|
||||
{
|
||||
Name: "name",
|
||||
PortLabel: "portlabel",
|
||||
Tags: []string{"tags"},
|
||||
Checks: []*structs.ServiceCheck{
|
||||
{
|
||||
Name: "checkname",
|
||||
Type: "checktype",
|
||||
Command: "checkcmd",
|
||||
Args: []string{"checkarg"},
|
||||
Path: "checkstr",
|
||||
Protocol: "checkproto",
|
||||
PortLabel: "checklabel",
|
||||
InitialStatus: "checkstatus",
|
||||
Method: "checkmethod",
|
||||
Header: map[string][]string{
|
||||
"checkheaderk": {"checkheaderv"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
require.Equal(t, exp, interpolated)
|
||||
}
|
||||
Reference in New Issue
Block a user