generated from LinuxSuRen/github-go
-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathparser_test.go
82 lines (77 loc) · 1.74 KB
/
parser_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
package version_test
import (
"testing"
"github.com/linuxsuren/http-downloader/pkg/version"
"github.com/stretchr/testify/assert"
)
func TestGetVersion(t *testing.T) {
tests := []struct {
name string
output string
expectVer string
}{{
name: "invalid",
output: "abc",
expectVer: "0.0.0",
}, {
name: "normal",
output: `minikube version: v1.28.0
commit: 986b1ebd987211ed16f8cc10aed7d2c42fc8392f`,
expectVer: "1.28.0",
}, {
name: "complex",
output: `
____ __.________
| |/ _/ __ \______
| < \____ / ___/
| | \ / /\___ \
|____|__ \ /____//____ >
\/ \/
Version: v0.26.3
Commit: 0893f13b3ca6b563dd0c38fdebaefdb8be594825
Date: 2022-08-04T05:18:24Z`,
expectVer: "0.26.3",
}, {
name: "without prefix v",
output: "git version 2.34.1",
expectVer: "2.34.1",
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := version.GetVersion(tt.output)
assert.Equal(t, tt.expectVer, result)
})
}
}
func TestGreatThan(t *testing.T) {
tests := []struct {
name string
target string
output string
expect bool
}{{
name: "normal",
target: "v1.28.1",
output: `minikube version: v1.28.0
commit: 986b1ebd987211ed16f8cc10aed7d2c42fc8392f`,
expect: true,
}, {
name: "normal",
target: "v1.28.0",
output: `minikube version: v1.28.1
commit: 986b1ebd987211ed16f8cc10aed7d2c42fc8392f`,
expect: false,
}, {
name: "version is equal",
target: "v1.28.0",
output: `minikube version: v1.28.0
commit: 986b1ebd987211ed16f8cc10aed7d2c42fc8392f`,
expect: false,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := version.GreatThan(tt.target, tt.output)
assert.Equal(t, tt.expect, result)
})
}
}