@@ -10,6 +10,7 @@ import (
10
10
rpc_server "github.com/docker/infrakit/pkg/rpc/server"
11
11
"github.com/docker/infrakit/pkg/spi/flavor"
12
12
"github.com/docker/infrakit/pkg/spi/instance"
13
+ testing_flavor "github.com/docker/infrakit/pkg/testing/flavor"
13
14
"github.com/docker/infrakit/pkg/types"
14
15
"github.com/stretchr/testify/require"
15
16
"io/ioutil"
@@ -27,41 +28,14 @@ func tempSocket() string {
27
28
return path .Join (dir , "flavor-impl-test" )
28
29
}
29
30
30
- type testPlugin struct {
31
- DoValidate func (flavorProperties * types.Any , allocation group_types.AllocationMethod ) error
32
- DoPrepare func (flavorProperties * types.Any , spec instance.Spec ,
33
- allocation group_types.AllocationMethod ) (instance.Spec , error )
34
- DoHealthy func (flavorProperties * types.Any , inst instance.Description ) (flavor.Health , error )
35
- DoDrain func (flavorProperties * types.Any , inst instance.Description ) error
36
- }
37
-
38
- func (t * testPlugin ) Validate (flavorProperties * types.Any , allocation group_types.AllocationMethod ) error {
39
- return t .DoValidate (flavorProperties , allocation )
40
- }
41
-
42
- func (t * testPlugin ) Prepare (flavorProperties * types.Any ,
43
- spec instance.Spec ,
44
- allocation group_types.AllocationMethod ) (instance.Spec , error ) {
45
-
46
- return t .DoPrepare (flavorProperties , spec , allocation )
47
- }
48
-
49
- func (t * testPlugin ) Healthy (flavorProperties * types.Any , inst instance.Description ) (flavor.Health , error ) {
50
- return t .DoHealthy (flavorProperties , inst )
51
- }
52
-
53
- func (t * testPlugin ) Drain (flavorProperties * types.Any , inst instance.Description ) error {
54
- return t .DoDrain (flavorProperties , inst )
55
- }
56
-
57
31
func TestFlavorPluginValidate (t * testing.T ) {
58
32
socketPath := tempSocket ()
59
33
name := filepath .Base (socketPath )
60
34
61
35
inputFlavorPropertiesActual := make (chan * types.Any , 1 )
62
36
inputFlavorProperties := types .AnyString (`{"flavor":"zookeeper","role":"leader"}` )
63
37
64
- server , err := rpc_server .StartPluginAtPath (socketPath , PluginServer (& testPlugin {
38
+ server , err := rpc_server .StartPluginAtPath (socketPath , PluginServer (& testing_flavor. Plugin {
65
39
DoValidate : func (flavorProperties * types.Any , allocation group_types.AllocationMethod ) error {
66
40
inputFlavorPropertiesActual <- flavorProperties
67
41
return nil
@@ -83,7 +57,7 @@ func TestFlavorPluginValidateError(t *testing.T) {
83
57
inputFlavorPropertiesActual := make (chan * types.Any , 1 )
84
58
inputFlavorProperties := types .AnyString (`{"flavor":"zookeeper","role":"leader"}` )
85
59
86
- server , err := rpc_server .StartPluginAtPath (socketPath , PluginServer (& testPlugin {
60
+ server , err := rpc_server .StartPluginAtPath (socketPath , PluginServer (& testing_flavor. Plugin {
87
61
DoValidate : func (flavorProperties * types.Any , allocation group_types.AllocationMethod ) error {
88
62
inputFlavorPropertiesActual <- flavorProperties
89
63
return errors .New ("something-went-wrong" )
@@ -111,7 +85,7 @@ func TestFlavorPluginPrepare(t *testing.T) {
111
85
Tags : map [string ]string {"foo" : "bar" },
112
86
}
113
87
114
- server , err := rpc_server .StartPluginAtPath (socketPath , PluginServer (& testPlugin {
88
+ server , err := rpc_server .StartPluginAtPath (socketPath , PluginServer (& testing_flavor. Plugin {
115
89
DoPrepare : func (
116
90
flavorProperties * types.Any ,
117
91
instanceSpec instance.Spec ,
@@ -150,7 +124,7 @@ func TestFlavorPluginPrepareError(t *testing.T) {
150
124
Tags : map [string ]string {"foo" : "bar" },
151
125
}
152
126
153
- server , err := rpc_server .StartPluginAtPath (socketPath , PluginServer (& testPlugin {
127
+ server , err := rpc_server .StartPluginAtPath (socketPath , PluginServer (& testing_flavor. Plugin {
154
128
DoPrepare : func (
155
129
flavorProperties * types.Any ,
156
130
instanceSpec instance.Spec ,
@@ -188,7 +162,7 @@ func TestFlavorPluginHealthy(t *testing.T) {
188
162
ID : instance .ID ("foo" ),
189
163
Tags : map [string ]string {"foo" : "bar" },
190
164
}
191
- server , err := rpc_server .StartPluginAtPath (socketPath , PluginServer (& testPlugin {
165
+ server , err := rpc_server .StartPluginAtPath (socketPath , PluginServer (& testing_flavor. Plugin {
192
166
DoHealthy : func (properties * types.Any , inst instance.Description ) (flavor.Health , error ) {
193
167
inputPropertiesActual <- properties
194
168
inputInstanceActual <- inst
@@ -217,7 +191,7 @@ func TestFlavorPluginHealthyError(t *testing.T) {
217
191
ID : instance .ID ("foo" ),
218
192
Tags : map [string ]string {"foo" : "bar" },
219
193
}
220
- server , err := rpc_server .StartPluginAtPath (socketPath , PluginServer (& testPlugin {
194
+ server , err := rpc_server .StartPluginAtPath (socketPath , PluginServer (& testing_flavor. Plugin {
221
195
DoHealthy : func (flavorProperties * types.Any , inst instance.Description ) (flavor.Health , error ) {
222
196
inputPropertiesActual <- flavorProperties
223
197
inputInstanceActual <- inst
@@ -246,7 +220,7 @@ func TestFlavorPluginDrain(t *testing.T) {
246
220
ID : instance .ID ("foo" ),
247
221
Tags : map [string ]string {"foo" : "bar" },
248
222
}
249
- server , err := rpc_server .StartPluginAtPath (socketPath , PluginServer (& testPlugin {
223
+ server , err := rpc_server .StartPluginAtPath (socketPath , PluginServer (& testing_flavor. Plugin {
250
224
DoDrain : func (properties * types.Any , inst instance.Description ) error {
251
225
inputPropertiesActual <- properties
252
226
inputInstanceActual <- inst
@@ -273,7 +247,7 @@ func TestFlavorPluginDrainError(t *testing.T) {
273
247
ID : instance .ID ("foo" ),
274
248
Tags : map [string ]string {"foo" : "bar" },
275
249
}
276
- server , err := rpc_server .StartPluginAtPath (socketPath , PluginServer (& testPlugin {
250
+ server , err := rpc_server .StartPluginAtPath (socketPath , PluginServer (& testing_flavor. Plugin {
277
251
DoDrain : func (flavorProperties * types.Any , inst instance.Description ) error {
278
252
inputPropertiesActual <- flavorProperties
279
253
inputInstanceActual <- inst
0 commit comments