Skip to content

Commit f2c3122

Browse files
committed
platforms: Format(): use path.Join() instead of joinNotEmpty()
path.Join() also skips empty components, making it the equivalent of this function. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent f12040b commit f2c3122

2 files changed

Lines changed: 12 additions & 23 deletions

File tree

platforms/platforms.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
package platforms
108108

109109
import (
110+
"path"
110111
"regexp"
111112
"runtime"
112113
"strconv"
@@ -246,20 +247,7 @@ func Format(platform specs.Platform) string {
246247
return "unknown"
247248
}
248249

249-
return joinNotEmpty(platform.OS, platform.Architecture, platform.Variant)
250-
}
251-
252-
func joinNotEmpty(s ...string) string {
253-
var ss []string
254-
for _, s := range s {
255-
if s == "" {
256-
continue
257-
}
258-
259-
ss = append(ss, s)
260-
}
261-
262-
return strings.Join(ss, "/")
250+
return path.Join(platform.OS, platform.Architecture, platform.Variant)
263251
}
264252

265253
// Normalize validates and translate the platform to the canonical value.

platforms/platforms_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package platforms
1818

1919
import (
20+
"path"
2021
"reflect"
2122
"runtime"
2223
"testing"
@@ -204,7 +205,7 @@ func TestParseSelector(t *testing.T) {
204205
OS: defaultOS,
205206
Architecture: "arm",
206207
},
207-
formatted: joinNotEmpty(defaultOS, "arm"),
208+
formatted: path.Join(defaultOS, "arm"),
208209
},
209210
{
210211
input: "armel",
@@ -213,31 +214,31 @@ func TestParseSelector(t *testing.T) {
213214
Architecture: "arm",
214215
Variant: "v6",
215216
},
216-
formatted: joinNotEmpty(defaultOS, "arm/v6"),
217+
formatted: path.Join(defaultOS, "arm/v6"),
217218
},
218219
{
219220
input: "armhf",
220221
expected: specs.Platform{
221222
OS: defaultOS,
222223
Architecture: "arm",
223224
},
224-
formatted: joinNotEmpty(defaultOS, "arm"),
225+
formatted: path.Join(defaultOS, "arm"),
225226
},
226227
{
227228
input: "Aarch64",
228229
expected: specs.Platform{
229230
OS: defaultOS,
230231
Architecture: "arm64",
231232
},
232-
formatted: joinNotEmpty(defaultOS, "arm64"),
233+
formatted: path.Join(defaultOS, "arm64"),
233234
},
234235
{
235236
input: "x86_64",
236237
expected: specs.Platform{
237238
OS: defaultOS,
238239
Architecture: "amd64",
239240
},
240-
formatted: joinNotEmpty(defaultOS, "amd64"),
241+
formatted: path.Join(defaultOS, "amd64"),
241242
},
242243
{
243244
input: "Linux/x86_64",
@@ -253,7 +254,7 @@ func TestParseSelector(t *testing.T) {
253254
OS: defaultOS,
254255
Architecture: "386",
255256
},
256-
formatted: joinNotEmpty(defaultOS, "386"),
257+
formatted: path.Join(defaultOS, "386"),
257258
},
258259
{
259260
input: "linux",
@@ -262,15 +263,15 @@ func TestParseSelector(t *testing.T) {
262263
Architecture: defaultArch,
263264
Variant: defaultVariant,
264265
},
265-
formatted: joinNotEmpty("linux", defaultArch, defaultVariant),
266+
formatted: path.Join("linux", defaultArch, defaultVariant),
266267
},
267268
{
268269
input: "s390x",
269270
expected: specs.Platform{
270271
OS: defaultOS,
271272
Architecture: "s390x",
272273
},
273-
formatted: joinNotEmpty(defaultOS, "s390x"),
274+
formatted: path.Join(defaultOS, "s390x"),
274275
},
275276
{
276277
input: "linux/s390x",
@@ -287,7 +288,7 @@ func TestParseSelector(t *testing.T) {
287288
Architecture: defaultArch,
288289
Variant: defaultVariant,
289290
},
290-
formatted: joinNotEmpty("darwin", defaultArch, defaultVariant),
291+
formatted: path.Join("darwin", defaultArch, defaultVariant),
291292
},
292293
} {
293294
t.Run(testcase.input, func(t *testing.T) {

0 commit comments

Comments
 (0)