-
Notifications
You must be signed in to change notification settings - Fork 5
/
depcharge_test.go
85 lines (70 loc) · 1.88 KB
/
depcharge_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
85
package main
import (
"fmt"
"github.com/integrii/flaggy"
"github.com/stretchr/testify/assert"
"os"
"testing"
)
const CoverLimit = 0.8
func TestMain(m *testing.M) {
// call flag.Parse() here if TestMain uses flags
rc := m.Run()
// rc 0 means we've passed,
// and CoverMode will be non empty if run with -cover
if rc == 0 && testing.CoverMode() != "" {
c := testing.Coverage()
val, strict := os.LookupEnv("COVER_STRICT")
if val == "false" || val == "0" {
strict = false
}
if strict {
if c < CoverLimit {
fmt.Println("Tests passed but coverage was below ", CoverLimit*100, "%")
rc = -1
} else {
fmt.Println("Strict coverage passed!")
}
}
}
os.Exit(rc)
}
var oldArgs []string
func TestDepMainDryRun(t *testing.T) {
oldArgs = os.Args
defer flaggy.ResetParser()
defer func() { os.Args = oldArgs }()
defer func() { mockDefaultAction = nil }()
called := 0
mockDefaultAction = func(complete chan<- bool, dep dep, perform perform) {
assert.Equal(t, "go", perform.Kind)
assert.True(t, perform.Force)
assert.True(t, perform.DryRun)
assert.Equal(t, "get", perform.Action[0])
assert.Equal(t, "{{get}}", perform.Action[1])
called++
complete <- true
}
os.Args = []string{"", "--kind=go", "--force", "--dryrun", "--", "get", "{{get}}"}
main()
assert.Equal(t, 5, called)
}
func TestDepMainForce(t *testing.T) {
oldArgs = os.Args
defer flaggy.ResetParser()
defer func() { os.Args = oldArgs }()
defer func() { mockDefaultAction = nil }()
called := 0
mockDefaultAction = func(complete chan<- bool, dep dep, perform perform) {
assert.Equal(t, "go", perform.Kind)
assert.True(t, perform.Force)
assert.False(t, perform.DryRun)
assert.Equal(t, "get", perform.Action[0])
assert.Equal(t, "{{get}}", perform.Action[1])
called++
complete <- true
}
os.Args = []string{"", "--force", "--", "go", "get", "{{get}}"}
main()
assert.Equal(t, 5, called)
}