forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli_version_test.go
60 lines (48 loc) · 1.55 KB
/
cli_version_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
package main
import (
"regexp"
"runtime"
"strings"
"github.com/alibaba/pouch/test/command"
"github.com/alibaba/pouch/test/environment"
"github.com/alibaba/pouch/version"
"github.com/go-check/check"
"github.com/gotestyourself/gotestyourself/icmd"
)
// PouchVersionSuite is the test suite for version CLI.
type PouchVersionSuite struct{}
func init() {
check.Suite(&PouchVersionSuite{})
}
// SetUpTest does common setup in the beginning of each test.
func (suite *PouchVersionSuite) SetUpTest(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
}
// TestPouchVersion is to verify pouch version.
//
// TODO: check more values if version functionality is ready.
func (suite *PouchVersionSuite) TestPouchVersion(c *check.C) {
res := command.PouchRun("version").Assert(c, icmd.Success)
kv := versionToKV(res.Combined())
c.Assert(kv["GoVersion"], check.Equals, runtime.Version())
c.Assert(kv["APIVersion"], check.Equals, version.APIVersion)
c.Assert(kv["Arch"], check.Equals, runtime.GOARCH)
c.Assert(kv["Os"], check.Equals, runtime.GOOS)
c.Assert(kv["Version"], check.Equals, version.Version)
}
// versionToKV reads version string into key-value mapping.
func versionToKV(version string) map[string]string {
res := make(map[string]string)
reg := regexp.MustCompile(`^\w+:`)
lines := strings.Split(version, "\n")
for _, line := range lines {
if strings.TrimSpace(line) == "" {
continue
}
if loc := reg.FindStringIndex(line); loc != nil {
k, v := line[:loc[1]-1], line[loc[1]:]
res[strings.TrimSpace(k)] = strings.TrimSpace(v)
}
}
return res
}