generated from octomation/go-module
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feature_test.go
97 lines (85 loc) · 2.04 KB
/
feature_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
86
87
88
89
90
91
92
93
94
95
96
97
package config_test
import (
"testing"
"github.com/stretchr/testify/assert"
. "go.octolab.org/toolkit/config"
)
func TestFeature_String(t *testing.T) {
tests := map[string]struct {
feature Feature
expected string
}{
"enabled": {Feature{Name: "feature", Enabled: true}, "feature=true"},
"disabled": {Feature{Name: "feature", Enabled: false}, "feature=false"},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
assert.Equal(t, test.expected, test.feature.String())
})
}
}
func TestFeatures_String(t *testing.T) {
tests := map[string]struct {
features Features
expected string
}{
"nil": {nil, "-"},
"empty": {make(Features, 0), "-"},
"with data": {
Features{{Name: "featureA", Enabled: true}, {Name: "featureB"}},
"featureA=true, featureB=false",
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
assert.Equal(t, test.expected, test.features.String())
})
}
}
func TestFeatures_FindByID(t *testing.T) {
var id = [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
tests := map[string]struct {
features Features
id [16]byte
expected Feature
}{
"nil": {nil, id, Feature{}},
"empty": {make(Features, 0), id, Feature{}},
"with data": {
Features{
{ID: id, Name: "featureA", Enabled: true},
{Name: "featureB"},
},
id,
Feature{ID: id, Name: "featureA", Enabled: true},
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
assert.Equal(t, test.expected, test.features.FindByID(test.id))
})
}
}
func TestFeatures_FindByName(t *testing.T) {
tests := map[string]struct {
features Features
name string
expected Feature
}{
"nil": {nil, "feature", Feature{}},
"empty": {make(Features, 0), "feature", Feature{}},
"with data": {
Features{
{Name: "featureA", Enabled: true},
{Name: "featureB"},
},
"featureA",
Feature{Name: "featureA", Enabled: true},
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
assert.Equal(t, test.expected, test.features.FindByName(test.name))
})
}
}