@@ -38,6 +38,17 @@ var testRESTAddress = Address{
38
38
},
39
39
}
40
40
41
+ var testRESTAddressWithAuthInject = Address {
42
+ Type : common .REST ,
43
+ Host : testHost ,
44
+ Port : testPort ,
45
+ RESTAddress : RESTAddress {
46
+ Path : testPath ,
47
+ HTTPMethod : testHTTPMethod ,
48
+ InjectEdgeXAuth : true ,
49
+ },
50
+ }
51
+
41
52
var testMQTTPubAddress = Address {
42
53
Type : common .MQTT ,
43
54
Host : testHost ,
@@ -61,6 +72,11 @@ func TestAddress_UnmarshalJSON(t *testing.T) {
61
72
testRESTAddress .Type , testRESTAddress .Host , testRESTAddress .Port ,
62
73
testRESTAddress .Path , testRESTAddress .HTTPMethod ,
63
74
)
75
+ restWithInjectJsonStr := fmt .Sprintf (
76
+ `{"type":"%s","host":"%s","port":%d,"path":"%s","httpMethod":"%s","injectEdgeXAuth":%v}` ,
77
+ testRESTAddressWithAuthInject .Type , testRESTAddressWithAuthInject .Host , testRESTAddressWithAuthInject .Port ,
78
+ testRESTAddressWithAuthInject .Path , testRESTAddressWithAuthInject .HTTPMethod , testRESTAddressWithAuthInject .InjectEdgeXAuth ,
79
+ )
64
80
mqttJsonStr := fmt .Sprintf (
65
81
`{"type":"%s","host":"%s","port":%d,"Publisher":"%s","Topic":"%s"}` ,
66
82
testMQTTPubAddress .Type , testMQTTPubAddress .Host , testMQTTPubAddress .Port ,
@@ -75,6 +91,7 @@ func TestAddress_UnmarshalJSON(t *testing.T) {
75
91
wantErr bool
76
92
}{
77
93
{"unmarshal RESTAddress with success" , testRESTAddress , []byte (restJsonStr ), false },
94
+ {"unmarshal RESTAddressWithAuthInject with success" , testRESTAddressWithAuthInject , []byte (restWithInjectJsonStr ), false },
78
95
{"unmarshal MQTTPubAddress with success" , testMQTTPubAddress , []byte (mqttJsonStr ), false },
79
96
{"unmarshal EmailAddress with success" , testEmailAddress , []byte (emailJsonStr ), false },
80
97
{"unmarshal invalid Address, empty data" , Address {}, []byte {}, true },
@@ -163,6 +180,16 @@ func TestAddress_marshalJSON(t *testing.T) {
163
180
`{"type":"%s","host":"%s","port":%d,"httpMethod":"%s"}` ,
164
181
restAddress .Type , restAddress .Host , restAddress .Port , restAddress .HTTPMethod ,
165
182
)
183
+ restAddressWithAuthInject := Address {
184
+ Type : common .REST ,
185
+ Host : testHost , Port : testPort ,
186
+ RESTAddress : RESTAddress {HTTPMethod : testHTTPMethod , InjectEdgeXAuth : true },
187
+ }
188
+ expectedRESTWithAuthInjectJsonStr := fmt .Sprintf (
189
+ `{"type":"%s","host":"%s","port":%d,"httpMethod":"%s","injectEdgeXAuth":%v}` ,
190
+ restAddressWithAuthInject .Type , restAddressWithAuthInject .Host , restAddressWithAuthInject .Port ,
191
+ restAddressWithAuthInject .HTTPMethod , restAddressWithAuthInject .InjectEdgeXAuth ,
192
+ )
166
193
mattAddress := Address {
167
194
Type : common .MQTT ,
168
195
Host : testHost , Port : testPort ,
@@ -192,6 +219,7 @@ func TestAddress_marshalJSON(t *testing.T) {
192
219
expectedJSONStr string
193
220
}{
194
221
{"marshal REST address" , restAddress , expectedRESTJsonStr },
222
+ {"marshal REST address with auth inject" , restAddressWithAuthInject , expectedRESTWithAuthInjectJsonStr },
195
223
{"marshal MQTT address" , mattAddress , expectedMQTTJsonStr },
196
224
{"marshal Email address" , emailAddress , expectedEmailJsonStr },
197
225
}
0 commit comments