mirror of
https://github.com/kemko/nomad.git
synced 2026-01-07 10:55:42 +03:00
Fixed the tests for jobspec
This commit is contained in:
committed by
Alex Dadgar
parent
51e3c9928b
commit
87f49c4f7f
@@ -8,6 +8,7 @@ import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/hcl"
|
||||
"github.com/hashicorp/hcl/hcl/ast"
|
||||
@@ -16,7 +17,7 @@ import (
|
||||
)
|
||||
|
||||
var reDynamicPorts *regexp.Regexp = regexp.MustCompile("^[a-zA-Z0-9_]+$")
|
||||
var errDynamicPorts = fmt.Errorf("DynamicPort label does not conform to naming requirements %s", reDynamicPorts.String())
|
||||
var errPortLabel = fmt.Errorf("Port label does not conform to naming requirements %s", reDynamicPorts.String())
|
||||
|
||||
// Parse parses the job spec from the given io.Reader.
|
||||
//
|
||||
@@ -513,11 +514,15 @@ func parseResources(result *structs.Resources, list *ast.ObjectList) error {
|
||||
}
|
||||
|
||||
func parsePorts(networkObj *ast.ObjectList, nw *structs.NetworkResource) error {
|
||||
portsObjList := networkObj.Filter("Port")
|
||||
portsObjList := networkObj.Filter("port")
|
||||
knownPortLabels := make(map[string]bool)
|
||||
for _, port := range portsObjList.Items {
|
||||
label := port.Keys[0].Token.Value().(string)
|
||||
if knownPortLabels[label] {
|
||||
if !reDynamicPorts.MatchString(label) {
|
||||
return errPortLabel
|
||||
}
|
||||
l := strings.ToLower(label)
|
||||
if knownPortLabels[l] {
|
||||
return fmt.Errorf("Found a port label collision: %s", label)
|
||||
}
|
||||
var p map[string]interface{}
|
||||
@@ -534,6 +539,7 @@ func parsePorts(networkObj *ast.ObjectList, nw *structs.NetworkResource) error {
|
||||
} else {
|
||||
nw.DynamicPorts = append(nw.DynamicPorts, res)
|
||||
}
|
||||
knownPortLabels[l] = true
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func TestParse(t *testing.T) {
|
||||
&structs.Task{
|
||||
Name: "outside",
|
||||
Driver: "java",
|
||||
Config: map[string]string{
|
||||
Config: map[string]interface{}{
|
||||
"jar": "s3://my-cool-store/foo.jar",
|
||||
},
|
||||
Meta: map[string]string{
|
||||
@@ -91,7 +91,7 @@ func TestParse(t *testing.T) {
|
||||
&structs.Task{
|
||||
Name: "binstore",
|
||||
Driver: "docker",
|
||||
Config: map[string]string{
|
||||
Config: map[string]interface{}{
|
||||
"image": "hashicorp/binstore",
|
||||
},
|
||||
Env: map[string]string{
|
||||
@@ -104,8 +104,8 @@ func TestParse(t *testing.T) {
|
||||
Networks: []*structs.NetworkResource{
|
||||
&structs.NetworkResource{
|
||||
MBits: 100,
|
||||
ReservedPorts: []int{1, 2, 3},
|
||||
DynamicPorts: []string{"http", "https", "admin"},
|
||||
ReservedPorts: []structs.Port{{"one", 1}, {"two", 2}, {"three", 3}},
|
||||
DynamicPorts: []structs.Port{{"http", 0}, {"https", 0}, {"admin", 0}},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -113,7 +113,7 @@ func TestParse(t *testing.T) {
|
||||
&structs.Task{
|
||||
Name: "storagelocker",
|
||||
Driver: "java",
|
||||
Config: map[string]string{
|
||||
Config: map[string]interface{}{
|
||||
"image": "hashicorp/storagelocker",
|
||||
},
|
||||
Resources: &structs.Resources{
|
||||
@@ -256,8 +256,8 @@ func TestBadPorts(t *testing.T) {
|
||||
|
||||
_, err = ParseFile(path)
|
||||
|
||||
if !strings.Contains(err.Error(), errDynamicPorts.Error()) {
|
||||
t.Fatalf("\nExpected error\n %s\ngot\n %v", errDynamicPorts, err)
|
||||
if !strings.Contains(err.Error(), errPortLabel.Error()) {
|
||||
t.Fatalf("\nExpected error\n %s\ngot\n %v", errPortLabel, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,8 +42,17 @@ job "binstore-storagelocker" {
|
||||
|
||||
network {
|
||||
mbits = "100"
|
||||
reserved_ports = [1,2,3]
|
||||
dynamic_ports = ["this_is_aport", "this#is$not-a!port"]
|
||||
port "one" {
|
||||
static = 1
|
||||
}
|
||||
port "two" {
|
||||
static = 2
|
||||
}
|
||||
port "three" {
|
||||
static = 3
|
||||
}
|
||||
port "this_is_aport" {}
|
||||
port ""{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,8 +51,18 @@ job "binstore-storagelocker" {
|
||||
|
||||
network {
|
||||
mbits = "100"
|
||||
reserved_ports = [1,2,3]
|
||||
dynamic_ports = ["http", "https", "admin"]
|
||||
port "one" {
|
||||
static = 1
|
||||
}
|
||||
port "two" {
|
||||
static = 2
|
||||
}
|
||||
port "three" {
|
||||
static = 3
|
||||
}
|
||||
port "http" {}
|
||||
port "https" {}
|
||||
port "admin" {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,8 +42,18 @@ job "binstore-storagelocker" {
|
||||
|
||||
network {
|
||||
mbits = "100"
|
||||
reserved_ports = [1,2,3]
|
||||
dynamic_ports = ["Http", "http", "HTTP"]
|
||||
port "one" {
|
||||
static = 1
|
||||
}
|
||||
port "two" {
|
||||
static = 2
|
||||
}
|
||||
port "three" {
|
||||
static = 3
|
||||
}
|
||||
port "Http" {}
|
||||
port "http" {}
|
||||
port "HTTP" {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user