11package main
22
33import (
4- "encoding/json"
54 "errors"
65 "testing"
76
87 mock_flavor "github.com/docker/infrakit/pkg/mock/spi/flavor"
98 "github.com/docker/infrakit/pkg/plugin"
109 "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"
1211 "github.com/docker/infrakit/pkg/spi/flavor"
1312 "github.com/docker/infrakit/pkg/spi/instance"
13+ "github.com/docker/infrakit/pkg/types"
1414 "github.com/golang/mock/gomock"
1515 "github.com/stretchr/testify/require"
1616)
1717
18- func jsonPtr (v string ) * json.RawMessage {
19- j := json .RawMessage (v )
20- return & j
21- }
22-
2318func logicalID (v string ) * instance.LogicalID {
2419 id := instance .LogicalID (v )
2520 return & id
2621}
2722
2823var inst = instance.Spec {
29- Properties : jsonPtr ("{}" ),
24+ Properties : types . AnyString ("{}" ),
3025 Tags : map [string ]string {},
3126 Init : "" ,
3227 LogicalID : logicalID ("id" ),
@@ -54,7 +49,7 @@ func TestMergeBehavior(t *testing.T) {
5449
5550 combo := NewPlugin (pluginLookup (plugins ))
5651
57- flavorProperties := json . RawMessage (`{
52+ flavorProperties := types . AnyString (`{
5853 "Flavors": [
5954 {
6055 "Plugin": "a",
@@ -67,25 +62,25 @@ func TestMergeBehavior(t *testing.T) {
6762 ]
6863 }` )
6964
70- allocation := types .AllocationMethod {Size : 1 }
65+ allocation := group_types .AllocationMethod {Size : 1 }
7166
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 {
7368 Properties : inst .Properties ,
7469 Tags : map [string ]string {"a" : "1" , "c" : "4" },
7570 Init : "init data a" ,
7671 LogicalID : inst .LogicalID ,
7772 Attachments : []instance.Attachment {{ID : "a" , Type : "nic" }},
7873 }, nil )
7974
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 {
8176 Properties : inst .Properties ,
8277 Tags : map [string ]string {"b" : "2" , "c" : "5" },
8378 Init : "init data b" ,
8479 LogicalID : inst .LogicalID ,
8580 Attachments : []instance.Attachment {{ID : "b" , Type : "gpu" }},
8681 }, nil )
8782
88- result , err := combo .Prepare (flavorProperties , inst , types .AllocationMethod {Size : 1 })
83+ result , err := combo .Prepare (flavorProperties , inst , group_types .AllocationMethod {Size : 1 })
8984 require .NoError (t , err )
9085
9186 expected := instance.Spec {
@@ -102,7 +97,7 @@ func TestMergeNoLogicalID(t *testing.T) {
10297 // Tests regression of a bug where a zero value was returned for the LogicalID despite nil being passed.
10398
10499 inst = instance.Spec {
105- Properties : jsonPtr ("{}" ),
100+ Properties : types . AnyString ("{}" ),
106101 Tags : map [string ]string {},
107102 Init : "" ,
108103 Attachments : []instance.Attachment {{ID : "att1" , Type : "nic" }},
@@ -118,7 +113,7 @@ func TestMergeNoLogicalID(t *testing.T) {
118113
119114 combo := NewPlugin (pluginLookup (plugins ))
120115
121- flavorProperties := json . RawMessage (`{
116+ flavorProperties := types . AnyString (`{
122117 "Flavors": [
123118 {
124119 "Plugin": "a",
@@ -131,25 +126,25 @@ func TestMergeNoLogicalID(t *testing.T) {
131126 ]
132127 }` )
133128
134- allocation := types .AllocationMethod {Size : 1 }
129+ allocation := group_types .AllocationMethod {Size : 1 }
135130
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 {
137132 Properties : inst .Properties ,
138133 Tags : map [string ]string {"a" : "1" , "c" : "4" },
139134 Init : "init data a" ,
140135 LogicalID : inst .LogicalID ,
141136 Attachments : []instance.Attachment {{ID : "a" , Type : "nic" }},
142137 }, nil )
143138
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 {
145140 Properties : inst .Properties ,
146141 Tags : map [string ]string {"b" : "2" , "c" : "5" },
147142 Init : "init data b" ,
148143 LogicalID : inst .LogicalID ,
149144 Attachments : []instance.Attachment {{ID : "b" , Type : "gpu" }},
150145 }, nil )
151146
152- result , err := combo .Prepare (flavorProperties , inst , types .AllocationMethod {Size : 1 })
147+ result , err := combo .Prepare (flavorProperties , inst , group_types .AllocationMethod {Size : 1 })
153148 require .NoError (t , err )
154149
155150 expected := instance.Spec {
0 commit comments