From a16b030e92fa06795015888145d3e7fcf662c41a Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Mon, 14 Mar 2016 17:54:49 -0700 Subject: [PATCH] Add two tests for invalid service names --- nomad/structs/structs_test.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index dbfe88686..07a532575 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -519,7 +519,7 @@ func TestInvalidServiceCheck(t *testing.T) { }, } if err := s.Validate(); err == nil { - t.Fatalf("Service should be invalid") + t.Fatalf("Service should be invalid (invalid type)") } s = Service{ @@ -527,7 +527,23 @@ func TestInvalidServiceCheck(t *testing.T) { PortLabel: "bar", } if err := s.Validate(); err == nil { - t.Fatalf("Service should be invalid: %v", err) + t.Fatalf("Service should be invalid (contains a dot): %v", err) + } + + s = Service{ + Name: "-my-service", + PortLabel: "bar", + } + if err := s.Validate(); err == nil { + t.Fatalf("Service should be invalid (begins with a hyphen): %v", err) + } + + s = Service{ + Name: "abcdef0123456789-abcdef0123456789-abcdef0123456789-abcdef0123456", + PortLabel: "bar", + } + if err := s.Validate(); err == nil { + t.Fatalf("Service should be invalid (too long): %v", err) } }