-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
145 lines (125 loc) · 3.43 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package anser
import (
"testing"
"github.com/deciduosity/anser/client"
"github.com/deciduosity/anser/mock"
"github.com/deciduosity/anser/model"
"github.com/deciduosity/birch"
"github.com/stretchr/testify/require"
)
func TestApplicationConstructor(t *testing.T) {
require := require.New(t) // nolint
env := mock.NewEnvironment()
require.NotNil(env)
///////////////////////////////////
//
// the constructor should return errors without proper inputs
app, err := NewApplication(nil, nil)
require.Error(err)
require.Nil(app)
app, err = NewApplication(env, nil)
require.Error(err)
require.Nil(app)
conf := &model.Configuration{}
app, err = NewApplication(nil, conf)
require.Error(err)
require.Nil(app)
///////////////////////////////////
//
// configure a valid, noop configuration without any generators defined
app, err = NewApplication(env, conf)
require.NoError(err)
require.NotNil(app)
require.Len(app.Generators, 0)
///////////////////////////////////
//
// Configure a working and valid populated configuration, with all three types.
conf.SimpleMigrations = []model.ConfigurationSimpleMigration{
{
Options: model.GeneratorOptions{
JobID: "foo-0",
NS: model.Namespace{DB: "db", Collection: "coll"},
Query: map[string]interface{}{"_id": "1"}},
Update: map[string]interface{}{"$set": 1},
},
}
env.MigrationRegistry["manualOne"] = func(c client.Client, doc *birch.Document) error { return nil }
conf.ManualMigrations = []model.ConfigurationManualMigration{
{
Options: model.GeneratorOptions{
JobID: "foo-1",
NS: model.Namespace{DB: "db", Collection: "coll"},
Query: map[string]interface{}{"_id": "1"}},
Name: "manualOne",
},
}
conf.StreamMigrations = []model.ConfigurationManualMigration{
{
Options: model.GeneratorOptions{
JobID: "foo-2",
NS: model.Namespace{DB: "db", Collection: "coll"},
Query: map[string]interface{}{"_id": "1"}},
Name: "streamOne",
},
}
app, err = NewApplication(env, conf)
require.NoError(err)
require.NotNil(app)
require.Len(app.Generators, 3)
///////////////////////////////////
//
// construct invalid migrations, and ensure that it errors
conf.SimpleMigrations = []model.ConfigurationSimpleMigration{
{
Options: model.GeneratorOptions{
JobID: "foo-3",
NS: model.Namespace{DB: "db", Collection: "coll"},
Query: map[string]interface{}{},
},
Update: map[string]interface{}{},
},
{
Options: model.GeneratorOptions{
JobID: "foo-4",
NS: model.Namespace{DB: "db", Collection: "coll"},
Query: map[string]interface{}{},
},
},
{
Options: model.GeneratorOptions{},
Update: map[string]interface{}{},
},
{
Options: model.GeneratorOptions{},
},
}
conf.ManualMigrations = []model.ConfigurationManualMigration{
{
Options: model.GeneratorOptions{
JobID: "foo-5",
NS: model.Namespace{DB: "db", Collection: "coll"},
Query: map[string]interface{}{"_id": "1"}},
Name: "manualTwo",
},
{
Options: model.GeneratorOptions{},
Name: "manualOne",
},
}
conf.StreamMigrations = []model.ConfigurationManualMigration{
{
Options: model.GeneratorOptions{
JobID: "foo-6",
NS: model.Namespace{DB: "db", Collection: "coll"},
Query: map[string]interface{}{"_id": "1"}},
Name: "streamTwo",
},
{
Options: model.GeneratorOptions{},
Name: "streamOne",
},
}
app, err = NewApplication(env, conf)
require.Error(err)
require.Nil(app)
}