-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat_test.go
More file actions
113 lines (96 loc) · 4.62 KB
/
format_test.go
File metadata and controls
113 lines (96 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package platforms
import (
"errors"
"testing"
)
func TestFormat(t *testing.T) {
tests := []struct {
eco Ecosystem
plat Platform
want string
}{
// x86_64 Linux GNU
{Go, Platform{Arch: "x86_64", OS: "linux"}, "linux/amd64"},
{Node, Platform{Arch: "x86_64", OS: "linux"}, "linux-x64"},
{Rust, Platform{Arch: "x86_64", OS: "linux", Vendor: "unknown", ABI: "gnu"}, "x86_64-unknown-linux-gnu"},
{RubyGems, Platform{Arch: "x86_64", OS: "linux"}, "x86_64-linux"},
{Python, Platform{Arch: "x86_64", OS: "linux", ABI: "gnu"}, "manylinux_2_17_x86_64"},
{Python, Platform{Arch: "x86_64", OS: "linux", ABI: "gnu", LibCVersion: "2.28"}, "manylinux_2_28_x86_64"},
{Debian, Platform{Arch: "x86_64", OS: "linux", ABI: "gnu"}, "x86_64-linux-gnu"},
{LLVM, Platform{Arch: "x86_64", OS: "linux", Vendor: "pc", ABI: "gnu"}, "x86_64-pc-linux-gnu"},
// ARM64 macOS
{Go, Platform{Arch: "aarch64", OS: "darwin"}, "darwin/arm64"},
{Node, Platform{Arch: "aarch64", OS: "darwin"}, "darwin-arm64"},
{Rust, Platform{Arch: "aarch64", OS: "darwin", Vendor: "apple"}, "aarch64-apple-darwin"},
{RubyGems, Platform{Arch: "aarch64", OS: "darwin"}, "arm64-darwin"},
{Python, Platform{Arch: "aarch64", OS: "darwin", Vendor: "apple"}, "macosx_11_0_arm64"},
{Python, Platform{Arch: "aarch64", OS: "darwin", Vendor: "apple", OSVersion: "14.0"}, "macosx_14_0_arm64"},
{LLVM, Platform{Arch: "aarch64", OS: "darwin", Vendor: "apple"}, "aarch64-apple-darwin"},
// x86_64 Windows MSVC
{Go, Platform{Arch: "x86_64", OS: "windows"}, "windows/amd64"},
{Node, Platform{Arch: "x86_64", OS: "windows"}, "win32-x64"},
{Rust, Platform{Arch: "x86_64", OS: "windows", Vendor: "pc", ABI: "msvc"}, "x86_64-pc-windows-msvc"},
{Python, Platform{Arch: "x86_64", OS: "windows"}, "win_amd64"},
{LLVM, Platform{Arch: "x86_64", OS: "windows", Vendor: "pc", ABI: "msvc"}, "x86_64-pc-windows-msvc"},
// ARM64 Linux GNU
{Go, Platform{Arch: "aarch64", OS: "linux"}, "linux/arm64"},
{Rust, Platform{Arch: "aarch64", OS: "linux", Vendor: "unknown", ABI: "gnu"}, "aarch64-unknown-linux-gnu"},
{Debian, Platform{Arch: "aarch64", OS: "linux", ABI: "gnu"}, "aarch64-linux-gnu"},
// Musl
{Rust, Platform{Arch: "x86_64", OS: "linux", Vendor: "unknown", ABI: "musl"}, "x86_64-unknown-linux-musl"},
{RubyGems, Platform{Arch: "x86_64", OS: "linux", ABI: "musl"}, "x86_64-linux-musl"},
{Python, Platform{Arch: "x86_64", OS: "linux", ABI: "musl"}, "musllinux_1_1_x86_64"},
// i686 Windows
{Python, Platform{Arch: "i686", OS: "windows"}, "win32"},
// FreeBSD
{Go, Platform{Arch: "x86_64", OS: "freebsd"}, "freebsd/amd64"},
{Rust, Platform{Arch: "x86_64", OS: "freebsd"}, "x86_64-unknown-freebsd"},
// Compose fallback for unlisted platforms
{Go, Platform{Arch: "mips64le", OS: "linux"}, "linux/mips64le"},
{Rust, Platform{Arch: "s390x", OS: "linux", Vendor: "unknown", ABI: "gnu"}, "s390x-unknown-linux-gnu"},
// NuGet
{NuGet, Platform{Arch: "x86_64", OS: "linux"}, "linux-x64"},
{NuGet, Platform{Arch: "x86_64", OS: "linux", ABI: "musl"}, "linux-musl-x64"},
{NuGet, Platform{Arch: "aarch64", OS: "darwin"}, "osx-arm64"},
{NuGet, Platform{Arch: "x86_64", OS: "windows"}, "win-x64"},
// vcpkg
{Vcpkg, Platform{Arch: "x86_64", OS: "linux"}, "x64-linux"},
{Vcpkg, Platform{Arch: "aarch64", OS: "darwin"}, "arm64-osx"},
{Vcpkg, Platform{Arch: "x86_64", OS: "windows"}, "x64-windows"},
// Swift
{Swift, Platform{Arch: "aarch64", OS: "darwin", Vendor: "apple"}, "aarch64-apple-darwin"},
{Swift, Platform{Arch: "x86_64", OS: "linux", Vendor: "unknown", ABI: "gnu"}, "x86_64-unknown-linux-gnu"},
// Kotlin
{Kotlin, Platform{Arch: "x86_64", OS: "linux"}, "linuxX64"},
{Kotlin, Platform{Arch: "aarch64", OS: "darwin"}, "macosArm64"},
// Maven
{Maven, Platform{Arch: "x86_64", OS: "linux"}, "linux-x86_64"},
{Maven, Platform{Arch: "aarch64", OS: "darwin"}, "osx-aarch_64"},
}
for _, tt := range tests {
t.Run(string(tt.eco)+"/"+tt.want, func(t *testing.T) {
got, err := Format(tt.eco, tt.plat)
if err != nil {
t.Fatalf("Format(%s, %+v) error: %v", tt.eco, tt.plat, err)
}
if got != tt.want {
t.Errorf("Format(%s, %+v) = %q, want %q", tt.eco, tt.plat, got, tt.want)
}
})
}
}
func TestFormatNoMapping(t *testing.T) {
// Darwin is not supported by Debian.
_, err := Format(Debian, Platform{Arch: "x86_64", OS: "darwin"})
var e *ErrNoMapping
if !errors.As(err, &e) {
t.Fatalf("expected ErrNoMapping, got %v", err)
}
}
func TestFormatUnknownEcosystem(t *testing.T) {
_, err := Format("bogus", Platform{Arch: "x86_64", OS: "linux"})
var e *ErrUnknownEcosystem
if !errors.As(err, &e) {
t.Fatalf("expected ErrUnknownEcosystem, got %v", err)
}
}