mirror of https://github.com/docker/docs.git
return empty key, val strings and nil err when given an empty string in parseLine()
add Centos test for ParseOsRelease() and blank line in test for ParseLine() Signed-off-by: Aaron Welch <welch@packet.net>
This commit is contained in:
parent
f010a7bb80
commit
5c3ac31931
|
@ -50,6 +50,10 @@ func (osr *OsRelease) setIfPossible(key, val string) error {
|
|||
}
|
||||
|
||||
func parseLine(osrLine string) (string, string, error) {
|
||||
if osrLine == "" {
|
||||
return "", "", nil
|
||||
}
|
||||
|
||||
vals := strings.Split(osrLine, "=")
|
||||
if len(vals) != 2 {
|
||||
return "", "", fmt.Errorf("Expected %s to split by '=' char into two strings, instead got %d strings", osrLine, len(vals))
|
||||
|
|
|
@ -18,7 +18,8 @@ PRETTY_NAME="Ubuntu 14.04 LTS"
|
|||
VERSION_ID="14.04"
|
||||
HOME_URL="http://www.ubuntu.com/"
|
||||
SUPPORT_URL="http://help.ubuntu.com/"
|
||||
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"`)
|
||||
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
|
||||
`)
|
||||
gentoo = []byte(`NAME=Gentoo
|
||||
ID=gentoo
|
||||
PRETTY_NAME="Gentoo/Linux"
|
||||
|
@ -34,7 +35,19 @@ ID_LIKE=debian
|
|||
VERSION_ID="14.04"
|
||||
HOME_URL="http://www.ubuntu.com/"
|
||||
SUPPORT_URL="http://help.ubuntu.com/"
|
||||
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"`)
|
||||
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
|
||||
`)
|
||||
centos = []byte(`NAME="CentOS Linux"
|
||||
VERSION="7 (Core)"
|
||||
ID="centos"
|
||||
ID_LIKE="rhel fedora"
|
||||
VERSION_ID="7"
|
||||
PRETTY_NAME="CentOS Linux 7 (Core)"
|
||||
ANSI_COLOR="0;31"
|
||||
HOME_URL="https://www.centos.org/"
|
||||
BUG_REPORT_URL="https://bugs.centos.org/"
|
||||
|
||||
`)
|
||||
)
|
||||
|
||||
osr, err := NewOsRelease(ubuntuTrusty)
|
||||
|
@ -102,6 +115,27 @@ BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"`)
|
|||
if !reflect.DeepEqual(*osr, expectedOsr) {
|
||||
t.Fatal("Error with noPrettyName osr parsing: structs do not match")
|
||||
}
|
||||
|
||||
osr, err = NewOsRelease(centos)
|
||||
if err != nil {
|
||||
t.Fatal("Unexpected error parsing os release: %s", err)
|
||||
}
|
||||
|
||||
expectedOsr = OsRelease{
|
||||
Name: "CentOS Linux",
|
||||
Version: "7 (Core)",
|
||||
Id: "centos",
|
||||
IdLike: "rhel fedora",
|
||||
PrettyName: "CentOS Linux 7 (Core)",
|
||||
AnsiColor: "0;31",
|
||||
VersionId: "7",
|
||||
HomeUrl: "https://www.centos.org/",
|
||||
BugReportUrl: "https://bugs.centos.org/",
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(*osr, expectedOsr) {
|
||||
t.Fatal("Error with centos osr parsing: structs do not match")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseLine(t *testing.T) {
|
||||
|
@ -109,6 +143,7 @@ func TestParseLine(t *testing.T) {
|
|||
withQuotes = "ID=\"ubuntu\""
|
||||
withoutQuotes = "ID=gentoo"
|
||||
wtf = "LOTS=OF=EQUALS"
|
||||
blank = ""
|
||||
)
|
||||
|
||||
key, val, err := parseLine(withQuotes)
|
||||
|
@ -135,4 +170,10 @@ func TestParseLine(t *testing.T) {
|
|||
if err == nil {
|
||||
t.Fatal("Expected to get an error on parseLine, got nil")
|
||||
}
|
||||
key, val, err = parseLine(blank)
|
||||
if key != "" || val != "" {
|
||||
t.Fatal("Expected empty response on parseLine, got key: %s val: %s", key, val)
|
||||
} else if err != nil {
|
||||
t.Fatal("Expected nil err response on parseLine, got %s", err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue