forked from yourheropaul/inj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datasource_reader_test.go
62 lines (44 loc) · 1.28 KB
/
datasource_reader_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
package inj
import (
"fmt"
"testing"
)
///////////////////////////////////////////////////////////////
// A mock DatasourceReader implementation
///////////////////////////////////////////////////////////////
type MockDatasourceReader struct {
stack map[string]interface{}
}
func NewMockDatasourceReader(data ...map[string]interface{}) *MockDatasourceReader {
d := &MockDatasourceReader{}
d.stack = make(map[string]interface{})
for _, datum := range data {
for k, v := range datum {
d.stack[k] = v
}
}
return d
}
func (d *MockDatasourceReader) Read(key string) (interface{}, error) {
if value, exists := d.stack[key]; exists {
return value, nil
}
return nil, fmt.Errorf("No stack entry for '%s'", key)
}
///////////////////////////////////////////////////////////////
// Unit tests for graph implementation
///////////////////////////////////////////////////////////////
func Test_TheDatasourceReaderWritesToTheDepdendency(t *testing.T) {
dep := dataSourceDep{}
ds := newMockDataSourceWithValues(t)
g := NewGraph()
g.AddDatasource(ds)
g.Provide(&dep)
assertNoGraphErrors(t, g)
if g, e := dep.StringValue, DEFAULT_STRING; g != e {
t.Errorf("Expected string '%s', got '%s'", e, g)
}
if dep.FuncValue == nil {
t.Errorf("Didn't get expected function instance")
}
}