-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion_test.go
More file actions
32 lines (29 loc) · 1003 Bytes
/
Copy pathversion_test.go
File metadata and controls
32 lines (29 loc) · 1003 Bytes
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
package main
import "testing"
// TestEffectivePluginVersion 锁死版本号来源:
// - CI 用 `-ldflags -X main.pluginVersion=<tag>` 注入发行版号时按注入值上报;
// - 注入为空(构建脚本变量写错、tag 名为空)时回落到默认版本,
// 避免管理端与注册信息里出现空版本号;
// - 注入值带首尾空白时也要修剪。
func TestEffectivePluginVersion(t *testing.T) {
original := pluginVersion
defer func() { pluginVersion = original }()
cases := []struct {
injected string
want string
}{
{"v1.2.3", "v1.2.3"},
{" v0.9.0 ", "v0.9.0"},
{"", defaultPluginVersion},
{" ", defaultPluginVersion},
}
for _, testCase := range cases {
pluginVersion = testCase.injected
if got := effectivePluginVersion(); got != testCase.want {
t.Fatalf("pluginVersion=%q → %q, want %q", testCase.injected, got, testCase.want)
}
}
if defaultPluginVersion == "" {
t.Fatal("defaultPluginVersion must not be empty")
}
}