-
Notifications
You must be signed in to change notification settings - Fork 8
/
config_test.go
84 lines (70 loc) · 1.98 KB
/
config_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 config
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/please-build/puku/kinds"
)
func TestGetKind(t *testing.T) {
c := Config{
LibKinds: map[string]*KindConfig{
"go_binary": {},
},
TestKinds: map[string]*KindConfig{
"service_acceptance_test": {},
},
ExcludeBuiltinKinds: []string{"proto_library"},
}
t.Run("default kind", func(t *testing.T) {
kind := c.GetKind("go_library")
require.NotNil(t, kind)
assert.Equal(t, kinds.Lib, kind.Type)
})
t.Run("overridden default kind", func(t *testing.T) {
kind := c.GetKind("go_binary")
require.NotNil(t, kind)
assert.Equal(t, kinds.Lib, kind.Type)
})
t.Run("excluded default kind", func(t *testing.T) {
kind := c.GetKind("proto_library")
assert.Nil(t, kind)
})
t.Run("custom kinds", func(t *testing.T) {
kind := c.GetKind("service_acceptance_test")
require.NotNil(t, kind)
assert.Equal(t, kinds.Test, kind.Type)
})
}
func TestGetStop(t *testing.T) {
ptr := func(val bool) *bool {
return &val
}
t.Run("at root", func(t *testing.T) {
t.Run("when stop is true then stop", func(t *testing.T) {
c := Config{Stop: ptr(true)}
assert.True(t, c.GetStop())
})
t.Run("when stop is false then don't stop", func(t *testing.T) {
c := Config{Stop: ptr(false)}
assert.False(t, c.GetStop())
})
t.Run("when stop is nil then don't stop", func(t *testing.T) {
c := Config{Stop: nil}
assert.False(t, c.GetStop())
})
})
t.Run("with base", func(t *testing.T) {
t.Run("nil base, nil child, don't stop", func(t *testing.T) {
c := Config{base: &Config{Stop: nil}, Stop: nil}
assert.False(t, c.GetStop())
})
t.Run("true base, false child, don't stop", func(t *testing.T) {
c := Config{base: &Config{Stop: ptr(true)}, Stop: ptr(false)}
assert.False(t, c.GetStop())
})
t.Run("true base, nil child, do stop", func(t *testing.T) {
c := Config{base: &Config{Stop: ptr(true)}, Stop: nil}
assert.True(t, c.GetStop())
})
})
}