-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepoprovider_test.go
130 lines (125 loc) · 3.71 KB
/
repoprovider_test.go
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package main
import (
"errors"
"testing"
)
func TestWeight(t *testing.T) {
tests := []struct {
name string
asset *Asset
weight int
}{
{
name: "node_exporter-1.8.2.linux-arm64.tar.gz",
asset: newAsset("node_exporter-1.8.2.linux-arm64.tar.gz", "", "linux", "arm64", false),
weight: 6,
},
{
name: "aerospike-prometheus-exporter_1.17.0_x86_64.tgz",
asset: newAsset("aerospike-prometheus-exporter_1.17.0_x86_64.tgz", "", "linux", "amd64", false),
weight: 4,
},
{
name: "prometheus-iotdb-exporter_1.1_linux_64bit.tar.gz",
asset: newAsset("prometheus-iotdb-exporter_1.1_linux_64bit.tar.gz", "", "linux", "amd64", false),
weight: 6,
},
{
name: "prometheus-exporter-linux-1.0.1.tgz",
asset: newAsset("prometheus-exporter-linux-1.0.1.tgz", "", "linux", "amd64", false),
weight: 4,
},
{
name: "couchdb-prometheus-exporter_30.10.1_Linux_x86_64.tar.gz",
asset: newAsset("couchdb-prometheus-exporter_30.10.1_Linux_x86_64.tar.gz", "", "linux", "amd64", false),
weight: 6,
},
{
name: "prosafe_exporter-v0.2.8-x86_64-lnx.zip",
asset: newAsset("prosafe_exporter-v0.2.8-x86_64-lnx.zip", "", "linux", "amd64", false),
weight: 6,
},
{
name: "beanstalkd_exporter-1.0.5.linux-amd64.sha256",
asset: newAsset("beanstalkd_exporter-1.0.5.linux-amd64.sha256", "", "linux", "amd64", false),
weight: 5,
},
{
name: "site24x7_exporter-1.1.1-aarch64-unknown-linux-gnu",
asset: newAsset("site24x7_exporter-1.1.1-aarch64-unknown-linux-gnu", "", "linux", "amd64", false),
weight: 4,
},
{
name: "php-fpm-exporter.linux.amd64.sha256.txt",
asset: newAsset("php-fpm-exporter.linux.amd64.sha256.txt", "", "linux", "amd64", false),
weight: 5,
},
{
name: "softether_exporter-v0.2.0-x86_64-lnx.zip",
asset: newAsset("softether_exporter-v0.2.0-x86_64-lnx.zip", "", "linux", "amd64", false),
weight: 6,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.asset.Weight(); got != tt.weight {
t.Errorf("%s, Asset.Weight() = %d, want %d", tt.name, got, tt.weight)
}
})
}
}
func TestFindMaxWeightAsset(t *testing.T) {
tests := []struct {
name string
assets Assets
want Asset
wantErr error
}{
{
name: "not musl",
assets: Assets{
*newAsset("monit-5.34.0-linux-x64.tar.gz", "", "linux", "amd64", false),
*newAsset("monit-5.34.0-linux-x64-musl.tar.gz", "", "linux", "amd64", false),
},
want: *newAsset("monit-5.34.0-linux-x64.tar.gz", "", "linux", "amd64", false),
wantErr: nil,
},
{
name: "musl",
assets: Assets{
*newAsset("monit-5.34.0-linux-x64.tar.gz", "", "linux", "amd64", true),
*newAsset("monit-5.34.0-linux-x64-musl.tar.gz", "", "linux", "amd64", true),
},
want: *newAsset("monit-5.34.0-linux-x64-musl.tar.gz", "", "linux", "amd64", true),
wantErr: nil,
},
{
name: "single max weight asset",
assets: Assets{
*newAsset("node_exporter-1.8.2.linux-amd64.tar.gz", "", "linux", "amd64", false),
*newAsset("node_exporter-1.8.2.linux-arm64.tar.gz", "", "linux", "amd64", false),
*newAsset("node_exporter-1.8.2.darwin-amd64.tar.gz", "", "linux", "amd64", false),
},
want: *newAsset("node_exporter-1.8.2.linux-amd64.tar.gz", "", "linux", "amd64", false),
wantErr: nil,
},
{
name: "no assets",
assets: Assets{},
want: Asset{},
wantErr: ErrNoAsset,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := tt.assets.FindMaxWeightAsset()
if !errors.Is(err, tt.wantErr) {
t.Errorf("FindMaxWeightAsset() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("FindMaxWeightAsset() = %v, want %v", got, tt.want)
}
})
}
}