@@ -3,6 +3,7 @@ package launch
3
3
import (
4
4
"testing"
5
5
6
+ "github.com/docker/infrakit/pkg/types"
6
7
"github.com/stretchr/testify/require"
7
8
)
8
9
@@ -14,16 +15,16 @@ type testConfig struct {
14
15
type testLauncher struct {
15
16
name string
16
17
t * testing.T
17
- callback func (* Config )
18
+ callback func (* types. Any )
18
19
}
19
20
20
21
func (l * testLauncher ) Name () string {
21
22
return l .name
22
23
}
23
24
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 ) {
25
26
rule := testConfig {}
26
- err := config .Unmarshal (& rule )
27
+ err := config .Decode (& rule )
27
28
if err != nil {
28
29
return nil , err
29
30
}
@@ -47,7 +48,7 @@ func TestMonitorLoopNoRules(t *testing.T) {
47
48
48
49
input <- StartPlugin {
49
50
Plugin : "test" ,
50
- Error : func (config * Config , e error ) {
51
+ Error : func (config * types. Any , e error ) {
51
52
errChan <- e
52
53
},
53
54
}
@@ -60,28 +61,23 @@ func TestMonitorLoopNoRules(t *testing.T) {
60
61
61
62
func TestMonitorLoopValidRule (t * testing.T ) {
62
63
63
- raw := & Config {}
64
64
config := & testConfig {
65
65
Cmd : "hello" ,
66
66
Args : []string {"world" , "hello" },
67
67
}
68
68
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
74
70
rule := Rule {
75
71
Plugin : "hello" ,
76
72
Launch : ExecRule {
77
73
Exec : "test" ,
78
- Properties : raw ,
74
+ Properties : types . AnyValueMust ( config ) ,
79
75
},
80
76
}
81
77
monitor := NewMonitor (& testLauncher {
82
78
name : "test" ,
83
79
t : t ,
84
- callback : func (c * Config ) {
80
+ callback : func (c * types. Any ) {
85
81
receivedArgs = c
86
82
},
87
83
}, []Rule {rule })
@@ -93,45 +89,38 @@ func TestMonitorLoopValidRule(t *testing.T) {
93
89
started := make (chan interface {})
94
90
input <- StartPlugin {
95
91
Plugin : "hello" ,
96
- Started : func (config * Config ) {
92
+ Started : func (config * types. Any ) {
97
93
close (started )
98
94
},
99
95
}
100
96
101
97
<- started
102
98
103
- expected := & Config {}
104
- err = expected .Marshal (config )
105
- require .NoError (t , err )
106
-
99
+ expected := types .AnyValueMust (config )
107
100
require .Equal (t , * expected , * receivedArgs )
108
101
109
102
monitor .Stop ()
110
103
}
111
104
112
105
func TestMonitorLoopRuleLookupBehavior (t * testing.T ) {
113
- raw := & Config {}
106
+
114
107
config := & testConfig {
115
108
Cmd : "hello" ,
116
109
Args : []string {"world" , "hello" },
117
110
}
118
111
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
124
113
rule := Rule {
125
114
Plugin : "hello" ,
126
115
Launch : ExecRule {
127
116
Exec : "test" ,
128
- Properties : raw ,
117
+ Properties : types . AnyValueMust ( config ) ,
129
118
},
130
119
}
131
120
monitor := NewMonitor (& testLauncher {
132
121
name : "test" ,
133
122
t : t ,
134
- callback : func (c * Config ) {
123
+ callback : func (c * types. Any ) {
135
124
receivedArgs = c
136
125
},
137
126
}, []Rule {rule })
@@ -143,17 +132,14 @@ func TestMonitorLoopRuleLookupBehavior(t *testing.T) {
143
132
started := make (chan interface {})
144
133
input <- StartPlugin {
145
134
Plugin : "hello" ,
146
- Started : func (config * Config ) {
135
+ Started : func (config * types. Any ) {
147
136
close (started )
148
137
},
149
138
}
150
139
151
140
<- started
152
141
153
- expected := & Config {}
154
- err = expected .Marshal (config )
155
- require .NoError (t , err )
156
-
142
+ expected := types .AnyValueMust (config )
157
143
require .Equal (t , * expected , * receivedArgs )
158
144
159
145
monitor .Stop ()
0 commit comments