Merge pull request #5821 from thaJeztah/simplify_platforms_format

platforms: Format(): use path.Join() instead of joinNotEmpty()
This commit is contained in:
Maksym Pavlenko 2021-08-02 10:22:29 -07:00 committed by GitHub
commit 7d4891783a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 23 deletions

View File

@ -107,6 +107,7 @@
package platforms package platforms
import ( import (
"path"
"regexp" "regexp"
"runtime" "runtime"
"strconv" "strconv"
@ -246,20 +247,7 @@ func Format(platform specs.Platform) string {
return "unknown" return "unknown"
} }
return joinNotEmpty(platform.OS, platform.Architecture, platform.Variant) return path.Join(platform.OS, platform.Architecture, platform.Variant)
}
func joinNotEmpty(s ...string) string {
var ss []string
for _, s := range s {
if s == "" {
continue
}
ss = append(ss, s)
}
return strings.Join(ss, "/")
} }
// Normalize validates and translate the platform to the canonical value. // Normalize validates and translate the platform to the canonical value.

View File

@ -17,6 +17,7 @@
package platforms package platforms
import ( import (
"path"
"reflect" "reflect"
"runtime" "runtime"
"testing" "testing"
@ -204,7 +205,7 @@ func TestParseSelector(t *testing.T) {
OS: defaultOS, OS: defaultOS,
Architecture: "arm", Architecture: "arm",
}, },
formatted: joinNotEmpty(defaultOS, "arm"), formatted: path.Join(defaultOS, "arm"),
}, },
{ {
input: "armel", input: "armel",
@ -213,7 +214,7 @@ func TestParseSelector(t *testing.T) {
Architecture: "arm", Architecture: "arm",
Variant: "v6", Variant: "v6",
}, },
formatted: joinNotEmpty(defaultOS, "arm/v6"), formatted: path.Join(defaultOS, "arm/v6"),
}, },
{ {
input: "armhf", input: "armhf",
@ -221,7 +222,7 @@ func TestParseSelector(t *testing.T) {
OS: defaultOS, OS: defaultOS,
Architecture: "arm", Architecture: "arm",
}, },
formatted: joinNotEmpty(defaultOS, "arm"), formatted: path.Join(defaultOS, "arm"),
}, },
{ {
input: "Aarch64", input: "Aarch64",
@ -229,7 +230,7 @@ func TestParseSelector(t *testing.T) {
OS: defaultOS, OS: defaultOS,
Architecture: "arm64", Architecture: "arm64",
}, },
formatted: joinNotEmpty(defaultOS, "arm64"), formatted: path.Join(defaultOS, "arm64"),
}, },
{ {
input: "x86_64", input: "x86_64",
@ -237,7 +238,7 @@ func TestParseSelector(t *testing.T) {
OS: defaultOS, OS: defaultOS,
Architecture: "amd64", Architecture: "amd64",
}, },
formatted: joinNotEmpty(defaultOS, "amd64"), formatted: path.Join(defaultOS, "amd64"),
}, },
{ {
input: "Linux/x86_64", input: "Linux/x86_64",
@ -253,7 +254,7 @@ func TestParseSelector(t *testing.T) {
OS: defaultOS, OS: defaultOS,
Architecture: "386", Architecture: "386",
}, },
formatted: joinNotEmpty(defaultOS, "386"), formatted: path.Join(defaultOS, "386"),
}, },
{ {
input: "linux", input: "linux",
@ -262,7 +263,7 @@ func TestParseSelector(t *testing.T) {
Architecture: defaultArch, Architecture: defaultArch,
Variant: defaultVariant, Variant: defaultVariant,
}, },
formatted: joinNotEmpty("linux", defaultArch, defaultVariant), formatted: path.Join("linux", defaultArch, defaultVariant),
}, },
{ {
input: "s390x", input: "s390x",
@ -270,7 +271,7 @@ func TestParseSelector(t *testing.T) {
OS: defaultOS, OS: defaultOS,
Architecture: "s390x", Architecture: "s390x",
}, },
formatted: joinNotEmpty(defaultOS, "s390x"), formatted: path.Join(defaultOS, "s390x"),
}, },
{ {
input: "linux/s390x", input: "linux/s390x",
@ -287,7 +288,7 @@ func TestParseSelector(t *testing.T) {
Architecture: defaultArch, Architecture: defaultArch,
Variant: defaultVariant, Variant: defaultVariant,
}, },
formatted: joinNotEmpty("darwin", defaultArch, defaultVariant), formatted: path.Join("darwin", defaultArch, defaultVariant),
}, },
} { } {
t.Run(testcase.input, func(t *testing.T) { t.Run(testcase.input, func(t *testing.T) {