mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 17:35:43 +03:00
Test createCheckReg
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -14,6 +15,7 @@ import (
|
||||
"github.com/hashicorp/consul/api"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
"github.com/kr/pretty"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -1352,3 +1354,45 @@ func TestIsNomadService(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestCreateCheckReg asserts Nomad ServiceCheck structs are properly converted
|
||||
// to Consul API AgentCheckRegistrations.
|
||||
func TestCreateCheckReg(t *testing.T) {
|
||||
check := &structs.ServiceCheck{
|
||||
Name: "name",
|
||||
Type: "http",
|
||||
Path: "/path",
|
||||
PortLabel: "label",
|
||||
Method: "POST",
|
||||
Header: map[string][]string{
|
||||
"Foo": {"bar"},
|
||||
},
|
||||
}
|
||||
|
||||
serviceID := "testService"
|
||||
checkID := check.Hash(serviceID)
|
||||
host := "localhost"
|
||||
port := 41111
|
||||
|
||||
expected := &api.AgentCheckRegistration{
|
||||
ID: checkID,
|
||||
Name: "name",
|
||||
ServiceID: serviceID,
|
||||
}
|
||||
expected.Timeout = "0s"
|
||||
expected.Interval = "0s"
|
||||
expected.HTTP = fmt.Sprintf("http://%s:%d/path", host, port)
|
||||
expected.Header = map[string][]string{
|
||||
"Foo": {"bar"},
|
||||
}
|
||||
expected.Method = "POST"
|
||||
|
||||
actual, err := createCheckReg(serviceID, checkID, check, host, port)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
if diff := pretty.Diff(actual, expected); len(diff) > 0 {
|
||||
t.Fatalf("diff:\n%s\n", strings.Join(diff, "\n"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user