/
show_version_test.go
68 lines (43 loc) · 1.19 KB
/
show_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
61
62
63
64
65
66
67
package libclimate_test
import (
libclimate "github.com/synesissoftware/libCLImate.Go"
"bytes"
"fmt"
"os"
"testing"
)
func Test_ShowVersion_1(t *testing.T) {
stm := new(bytes.Buffer)
argv := []string{ "bin/myapp", "--version" }
climate, err := libclimate.Init(func (cl *libclimate.Climate) (err error) {
cl.Version = "0.0.1"
return nil
});
if err != nil {
fmt.Fprintf(os.Stderr, "failed to create CLI parser: %v\n", err)
}
_, _ = climate.ParseAndVerify(argv, stm, stub_exiter{})
actual := stm.String()
expected := "myapp 0.0.1\n"
if expected != actual {
t.Errorf("expected '%v' != actual '%v'", expected, actual)
}
}
func Test_ShowVersion_2(t *testing.T) {
stm := new(bytes.Buffer)
argv := []string{ "bin/myapp", "--version" }
climate, err := libclimate.Init(func (cl *libclimate.Climate) (err error) {
cl.Version = []int{ 0, 1, 2 }
cl.VersionPrefix = "v"
return nil
});
if err != nil {
fmt.Fprintf(os.Stderr, "failed to create CLI parser: %v\n", err)
}
_, _ = climate.ParseAndVerify(argv, stm, stub_exiter{})
actual := stm.String()
expected := "myapp v0.1.2\n"
if expected != actual {
t.Errorf("expected '%v' != actual '%v'", expected, actual)
}
}