-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli_test.go
84 lines (80 loc) · 1.61 KB
/
cli_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
package goscon
import (
"path/filepath"
"testing"
)
func TestSetFormat(t *testing.T) {
o := CliOptions{}
_ = o.SetFormat("csv")
got := o.Format
want := "csv"
if got != want {
t.Fatalf("got %v, wanted %v", got, want)
}
_ = o.SetFormat("json")
got = o.Format
want = "json"
if got != want {
t.Fatalf("got %v, wanted %v", got, want)
}
err := o.SetFormat("txt")
if err == nil {
t.Fatalf("got %v, wanted %v", o.Format, want)
}
}
func TestCliApp(t *testing.T) {
filename := ""
dir := "sample"
format := "csv"
app, err := cliApp(filename, dir, format)
if err != nil {
t.Fatalf("error %+v", err)
}
got := app.IsBatch
want := true
if got != want {
t.Fatalf("got %v, wanted %v", got, want)
}
got2 := app.Batch
want2 := []string{}
if len(got2) != len(want2) {
t.Fatalf("got %v, wanted %v", got2, want2)
}
got3 := app.Dir
want3, _ := filepath.Abs(dir)
if got3 != want3 {
t.Fatalf("got %v, wanted %v", got3, want3)
}
got4 := app.File
want4 := ""
if got4 != want4 {
t.Fatalf("got %v, wanted %v", got4, want4)
}
got5 := app.Format
want5 := "csv"
if got5 != want5 {
t.Fatalf("got %v, wanted %v", got5, want5)
}
filename = "test.pdf"
dir = ""
format = "csv"
app, err = cliApp(filename, dir, format)
if err != nil {
t.Fatalf("error %+v", err)
}
got = app.IsBatch
want = false
if got != want {
t.Fatalf("got %v, wanted %v", got, want)
}
got3, _ = filepath.Abs(app.Dir)
want3, _ = filepath.Abs(dir)
if got3 != want3 {
t.Fatalf("got %v, wanted %v", got3, want3)
}
got4 = app.File
want4, _ = filepath.Abs(filename)
if got4 != want4 {
t.Fatalf("got %v, wanted %v", got4, want4)
}
}