1
1
package main
2
2
3
3
import (
4
- "encoding/json"
5
4
"errors"
6
5
"testing"
7
6
8
7
mock_flavor "github.com/docker/infrakit/pkg/mock/spi/flavor"
9
8
"github.com/docker/infrakit/pkg/plugin"
10
9
"github.com/docker/infrakit/pkg/plugin/group"
11
- "github.com/docker/infrakit/pkg/plugin/group/types"
10
+ group_types "github.com/docker/infrakit/pkg/plugin/group/types"
12
11
"github.com/docker/infrakit/pkg/spi/flavor"
13
12
"github.com/docker/infrakit/pkg/spi/instance"
13
+ "github.com/docker/infrakit/pkg/types"
14
14
"github.com/golang/mock/gomock"
15
15
"github.com/stretchr/testify/require"
16
16
)
17
17
18
- func jsonPtr (v string ) * json.RawMessage {
19
- j := json .RawMessage (v )
20
- return & j
21
- }
22
-
23
18
func logicalID (v string ) * instance.LogicalID {
24
19
id := instance .LogicalID (v )
25
20
return & id
26
21
}
27
22
28
23
var inst = instance.Spec {
29
- Properties : jsonPtr ("{}" ),
24
+ Properties : types . AnyString ("{}" ),
30
25
Tags : map [string ]string {},
31
26
Init : "" ,
32
27
LogicalID : logicalID ("id" ),
@@ -54,7 +49,7 @@ func TestMergeBehavior(t *testing.T) {
54
49
55
50
combo := NewPlugin (pluginLookup (plugins ))
56
51
57
- flavorProperties := json . RawMessage (`{
52
+ flavorProperties := types . AnyString (`{
58
53
"Flavors": [
59
54
{
60
55
"Plugin": "a",
@@ -67,25 +62,25 @@ func TestMergeBehavior(t *testing.T) {
67
62
]
68
63
}` )
69
64
70
- allocation := types .AllocationMethod {Size : 1 }
65
+ allocation := group_types .AllocationMethod {Size : 1 }
71
66
72
- a .EXPECT ().Prepare (json . RawMessage (`{"a": "1"}` ), inst , allocation ).Return (instance.Spec {
67
+ a .EXPECT ().Prepare (types . AnyString (`{"a": "1"}` ), inst , allocation ).Return (instance.Spec {
73
68
Properties : inst .Properties ,
74
69
Tags : map [string ]string {"a" : "1" , "c" : "4" },
75
70
Init : "init data a" ,
76
71
LogicalID : inst .LogicalID ,
77
72
Attachments : []instance.Attachment {{ID : "a" , Type : "nic" }},
78
73
}, nil )
79
74
80
- b .EXPECT ().Prepare (json . RawMessage (`{"b": "2"}` ), inst , allocation ).Return (instance.Spec {
75
+ b .EXPECT ().Prepare (types . AnyString (`{"b": "2"}` ), inst , allocation ).Return (instance.Spec {
81
76
Properties : inst .Properties ,
82
77
Tags : map [string ]string {"b" : "2" , "c" : "5" },
83
78
Init : "init data b" ,
84
79
LogicalID : inst .LogicalID ,
85
80
Attachments : []instance.Attachment {{ID : "b" , Type : "gpu" }},
86
81
}, nil )
87
82
88
- result , err := combo .Prepare (flavorProperties , inst , types .AllocationMethod {Size : 1 })
83
+ result , err := combo .Prepare (flavorProperties , inst , group_types .AllocationMethod {Size : 1 })
89
84
require .NoError (t , err )
90
85
91
86
expected := instance.Spec {
@@ -102,7 +97,7 @@ func TestMergeNoLogicalID(t *testing.T) {
102
97
// Tests regression of a bug where a zero value was returned for the LogicalID despite nil being passed.
103
98
104
99
inst = instance.Spec {
105
- Properties : jsonPtr ("{}" ),
100
+ Properties : types . AnyString ("{}" ),
106
101
Tags : map [string ]string {},
107
102
Init : "" ,
108
103
Attachments : []instance.Attachment {{ID : "att1" , Type : "nic" }},
@@ -118,7 +113,7 @@ func TestMergeNoLogicalID(t *testing.T) {
118
113
119
114
combo := NewPlugin (pluginLookup (plugins ))
120
115
121
- flavorProperties := json . RawMessage (`{
116
+ flavorProperties := types . AnyString (`{
122
117
"Flavors": [
123
118
{
124
119
"Plugin": "a",
@@ -131,25 +126,25 @@ func TestMergeNoLogicalID(t *testing.T) {
131
126
]
132
127
}` )
133
128
134
- allocation := types .AllocationMethod {Size : 1 }
129
+ allocation := group_types .AllocationMethod {Size : 1 }
135
130
136
- a .EXPECT ().Prepare (json . RawMessage (`{"a": "1"}` ), inst , allocation ).Return (instance.Spec {
131
+ a .EXPECT ().Prepare (types . AnyString (`{"a": "1"}` ), inst , allocation ).Return (instance.Spec {
137
132
Properties : inst .Properties ,
138
133
Tags : map [string ]string {"a" : "1" , "c" : "4" },
139
134
Init : "init data a" ,
140
135
LogicalID : inst .LogicalID ,
141
136
Attachments : []instance.Attachment {{ID : "a" , Type : "nic" }},
142
137
}, nil )
143
138
144
- b .EXPECT ().Prepare (json . RawMessage (`{"b": "2"}` ), inst , allocation ).Return (instance.Spec {
139
+ b .EXPECT ().Prepare (types . AnyString (`{"b": "2"}` ), inst , allocation ).Return (instance.Spec {
145
140
Properties : inst .Properties ,
146
141
Tags : map [string ]string {"b" : "2" , "c" : "5" },
147
142
Init : "init data b" ,
148
143
LogicalID : inst .LogicalID ,
149
144
Attachments : []instance.Attachment {{ID : "b" , Type : "gpu" }},
150
145
}, nil )
151
146
152
- result , err := combo .Prepare (flavorProperties , inst , types .AllocationMethod {Size : 1 })
147
+ result , err := combo .Prepare (flavorProperties , inst , group_types .AllocationMethod {Size : 1 })
153
148
require .NoError (t , err )
154
149
155
150
expected := instance.Spec {
0 commit comments