Merge pull request #18695 from dnephin/move_parse_link
Move ParseLink and validators into runconfig.parse where they are used
This commit is contained in:
commit
16870807fe
2 changed files with 0 additions and 55 deletions
|
@ -5,7 +5,6 @@ package parsers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -68,28 +67,6 @@ func ParsePortRange(ports string) (uint64, uint64, error) {
|
||||||
return start, end, nil
|
return start, end, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseLink parses and validates the specified string as a link format (name:alias)
|
|
||||||
func ParseLink(val string) (string, string, error) {
|
|
||||||
if val == "" {
|
|
||||||
return "", "", fmt.Errorf("empty string specified for links")
|
|
||||||
}
|
|
||||||
arr := strings.Split(val, ":")
|
|
||||||
if len(arr) > 2 {
|
|
||||||
return "", "", fmt.Errorf("bad format for links: %s", val)
|
|
||||||
}
|
|
||||||
if len(arr) == 1 {
|
|
||||||
return val, val, nil
|
|
||||||
}
|
|
||||||
// This is kept because we can actually get an HostConfig with links
|
|
||||||
// from an already created container and the format is not `foo:bar`
|
|
||||||
// but `/foo:/c1/bar`
|
|
||||||
if strings.HasPrefix(arr[0], "/") {
|
|
||||||
_, alias := path.Split(arr[1])
|
|
||||||
return arr[0][1:], alias, nil
|
|
||||||
}
|
|
||||||
return arr[0], arr[1], nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseUintList parses and validates the specified string as the value
|
// ParseUintList parses and validates the specified string as the value
|
||||||
// found in some cgroup file (e.g. `cpuset.cpus`, `cpuset.mems`), which could be
|
// found in some cgroup file (e.g. `cpuset.cpus`, `cpuset.mems`), which could be
|
||||||
// one of the formats below. Note that duplicates are actually allowed in the
|
// one of the formats below. Note that duplicates are actually allowed in the
|
||||||
|
|
|
@ -81,38 +81,6 @@ func TestParsePortRangeIncorrectStartRange(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseLink(t *testing.T) {
|
|
||||||
name, alias, err := ParseLink("name:alias")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Expected not to error out on a valid name:alias format but got: %v", err)
|
|
||||||
}
|
|
||||||
if name != "name" {
|
|
||||||
t.Fatalf("Link name should have been name, got %s instead", name)
|
|
||||||
}
|
|
||||||
if alias != "alias" {
|
|
||||||
t.Fatalf("Link alias should have been alias, got %s instead", alias)
|
|
||||||
}
|
|
||||||
// short format definition
|
|
||||||
name, alias, err = ParseLink("name")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Expected not to error out on a valid name only format but got: %v", err)
|
|
||||||
}
|
|
||||||
if name != "name" {
|
|
||||||
t.Fatalf("Link name should have been name, got %s instead", name)
|
|
||||||
}
|
|
||||||
if alias != "name" {
|
|
||||||
t.Fatalf("Link alias should have been name, got %s instead", alias)
|
|
||||||
}
|
|
||||||
// empty string link definition is not allowed
|
|
||||||
if _, _, err := ParseLink(""); err == nil || !strings.Contains(err.Error(), "empty string specified for links") {
|
|
||||||
t.Fatalf("Expected error 'empty string specified for links' but got: %v", err)
|
|
||||||
}
|
|
||||||
// more than two colons are not allowed
|
|
||||||
if _, _, err := ParseLink("link:alias:wrong"); err == nil || !strings.Contains(err.Error(), "bad format for links: link:alias:wrong") {
|
|
||||||
t.Fatalf("Expected error 'bad format for links: link:alias:wrong' but got: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParseUintList(t *testing.T) {
|
func TestParseUintList(t *testing.T) {
|
||||||
valids := map[string]map[int]bool{
|
valids := map[string]map[int]bool{
|
||||||
"": {},
|
"": {},
|
||||||
|
|
Loading…
Reference in a new issue