This repository was archived by the owner on May 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconditional_source_test.go
More file actions
64 lines (46 loc) · 1.52 KB
/
conditional_source_test.go
File metadata and controls
64 lines (46 loc) · 1.52 KB
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
package configo
import (
"testing"
"github.com/smartystreets/assertions/should"
"github.com/smartystreets/gunit"
)
func TestConditionalSourceFixture(t *testing.T) {
gunit.Run(new(ConditionalSourceFixture), t)
}
type ConditionalSourceFixture struct {
*gunit.Fixture
source *ConditionalSource
active bool
pairs []DefaultPair
}
func (this *ConditionalSourceFixture) Setup() {
this.active = true
}
func (this *ConditionalSourceFixture) TestEmptyKeyReportsNoValues() {
this.assertError(ErrKeyNotFound)
}
func (this *ConditionalSourceFixture) TestAddingMultipleStringsRetrievesAll() {
this.addValues("Hello,")
this.addValues("World!")
this.assertValues([]string{"Hello,", "World!"})
}
func (this *ConditionalSourceFixture) TestFalseConditionReportsNoValues() {
this.addValues("Hello, World!")
this.active = false
this.assertError(ErrKeyNotFound)
}
func (this *ConditionalSourceFixture) addValues(values ...interface{}) {
this.pairs = append(this.pairs, Default("key", values...))
}
func (this *ConditionalSourceFixture) assertValues(expected []string) {
this.source = NewConditionalSource(func() bool { return this.active }, this.pairs...)
values, err := this.source.Strings("key")
this.So(err, should.BeNil)
this.So(values, should.Resemble, expected)
}
func (this *ConditionalSourceFixture) assertError(expected error) {
this.source = NewConditionalSource(func() bool { return this.active }, this.pairs...)
values, err := this.source.Strings("key")
this.So(err, should.Equal, expected)
this.So(values, should.BeNil)
}