@@ -3,6 +3,7 @@ package launch
33import (
44 "testing"
55
6+ "github.com/docker/infrakit/pkg/types"
67 "github.com/stretchr/testify/require"
78)
89
@@ -14,16 +15,16 @@ type testConfig struct {
1415type testLauncher struct {
1516 name string
1617 t * testing.T
17- callback func (* Config )
18+ callback func (* types. Any )
1819}
1920
2021func (l * testLauncher ) Name () string {
2122 return l .name
2223}
2324
24- func (l * testLauncher ) Exec (name string , config * Config ) (<- chan error , error ) {
25+ func (l * testLauncher ) Exec (name string , config * types. Any ) (<- chan error , error ) {
2526 rule := testConfig {}
26- err := config .Unmarshal (& rule )
27+ err := config .Decode (& rule )
2728 if err != nil {
2829 return nil , err
2930 }
@@ -47,7 +48,7 @@ func TestMonitorLoopNoRules(t *testing.T) {
4748
4849 input <- StartPlugin {
4950 Plugin : "test" ,
50- Error : func (config * Config , e error ) {
51+ Error : func (config * types. Any , e error ) {
5152 errChan <- e
5253 },
5354 }
@@ -60,28 +61,23 @@ func TestMonitorLoopNoRules(t *testing.T) {
6061
6162func TestMonitorLoopValidRule (t * testing.T ) {
6263
63- raw := & Config {}
6464 config := & testConfig {
6565 Cmd : "hello" ,
6666 Args : []string {"world" , "hello" },
6767 }
6868
69- rawErr := raw .Marshal (config )
70- require .NoError (t , rawErr )
71- require .True (t , len ([]byte (* raw )) > 0 )
72-
73- var receivedArgs * Config
69+ var receivedArgs * types.Any
7470 rule := Rule {
7571 Plugin : "hello" ,
7672 Launch : ExecRule {
7773 Exec : "test" ,
78- Properties : raw ,
74+ Properties : types . AnyValueMust ( config ) ,
7975 },
8076 }
8177 monitor := NewMonitor (& testLauncher {
8278 name : "test" ,
8379 t : t ,
84- callback : func (c * Config ) {
80+ callback : func (c * types. Any ) {
8581 receivedArgs = c
8682 },
8783 }, []Rule {rule })
@@ -93,45 +89,38 @@ func TestMonitorLoopValidRule(t *testing.T) {
9389 started := make (chan interface {})
9490 input <- StartPlugin {
9591 Plugin : "hello" ,
96- Started : func (config * Config ) {
92+ Started : func (config * types. Any ) {
9793 close (started )
9894 },
9995 }
10096
10197 <- started
10298
103- expected := & Config {}
104- err = expected .Marshal (config )
105- require .NoError (t , err )
106-
99+ expected := types .AnyValueMust (config )
107100 require .Equal (t , * expected , * receivedArgs )
108101
109102 monitor .Stop ()
110103}
111104
112105func TestMonitorLoopRuleLookupBehavior (t * testing.T ) {
113- raw := & Config {}
106+
114107 config := & testConfig {
115108 Cmd : "hello" ,
116109 Args : []string {"world" , "hello" },
117110 }
118111
119- rawErr := raw .Marshal (config )
120- require .NoError (t , rawErr )
121- require .True (t , len ([]byte (* raw )) > 0 )
122-
123- var receivedArgs * Config
112+ var receivedArgs * types.Any
124113 rule := Rule {
125114 Plugin : "hello" ,
126115 Launch : ExecRule {
127116 Exec : "test" ,
128- Properties : raw ,
117+ Properties : types . AnyValueMust ( config ) ,
129118 },
130119 }
131120 monitor := NewMonitor (& testLauncher {
132121 name : "test" ,
133122 t : t ,
134- callback : func (c * Config ) {
123+ callback : func (c * types. Any ) {
135124 receivedArgs = c
136125 },
137126 }, []Rule {rule })
@@ -143,17 +132,14 @@ func TestMonitorLoopRuleLookupBehavior(t *testing.T) {
143132 started := make (chan interface {})
144133 input <- StartPlugin {
145134 Plugin : "hello" ,
146- Started : func (config * Config ) {
135+ Started : func (config * types. Any ) {
147136 close (started )
148137 },
149138 }
150139
151140 <- started
152141
153- expected := & Config {}
154- err = expected .Marshal (config )
155- require .NoError (t , err )
156-
142+ expected := types .AnyValueMust (config )
157143 require .Equal (t , * expected , * receivedArgs )
158144
159145 monitor .Stop ()
0 commit comments