@@ -56,16 +56,31 @@ func TestStringPropertyTextMsg(t *testing.T) {
56
56
propValue := "myValue"
57
57
58
58
// Test the empty value before the property is set.
59
- // TODO - it would be nicer if this was nil rather than empty string, however it
60
- // doesn't look like that is supported by the mq-golang library itself.
61
- assert .Equal (t , "" , * txtMsg .GetStringProperty (propName ))
59
+ assert .Nil (t , txtMsg .GetStringProperty (propName ))
62
60
63
61
// Test the ability to set properties before the message is sent.
64
- retErr := txtMsg .SetStringProperty (propName , propValue )
62
+ retErr := txtMsg .SetStringProperty (propName , & propValue )
65
63
assert .Nil (t , retErr )
66
64
assert .Equal (t , propValue , * txtMsg .GetStringProperty (propName ))
67
65
assert .Equal (t , msgBody , * txtMsg .GetText ())
68
66
67
+ // Send an empty string property as well
68
+ emptyPropName := "myEmptyString"
69
+ emptyPropValue := ""
70
+ retErr = txtMsg .SetStringProperty (emptyPropName , & emptyPropValue )
71
+ assert .Nil (t , retErr )
72
+ assert .Equal (t , emptyPropValue , * txtMsg .GetStringProperty (emptyPropName ))
73
+
74
+ // Set a property then try to unset it by setting to nil
75
+ unsetPropName := "mySendThenRemovedString"
76
+ unsetPropValue := "someValueThatWillBeOverwritten"
77
+ retErr = txtMsg .SetStringProperty (unsetPropName , & unsetPropValue )
78
+ assert .Nil (t , retErr )
79
+ assert .Equal (t , unsetPropValue , * txtMsg .GetStringProperty (unsetPropName ))
80
+ retErr = txtMsg .SetStringProperty (unsetPropName , nil )
81
+ assert .Nil (t , retErr )
82
+ assert .Nil (t , txtMsg .GetStringProperty (unsetPropName ))
83
+
69
84
// Set up objects for send/receive
70
85
queue := context .CreateQueue ("DEV.QUEUE.1" )
71
86
consumer , errCons := context .CreateConsumer (queue )
@@ -92,6 +107,13 @@ func TestStringPropertyTextMsg(t *testing.T) {
92
107
// Check property is available on received message.
93
108
assert .Equal (t , propValue , * rcvMsg .GetStringProperty (propName ))
94
109
110
+ // Check the empty string property.
111
+ assert .Equal (t , emptyPropValue , * rcvMsg .GetStringProperty (emptyPropName ))
112
+
113
+ // Properties that are not set should return nil
114
+ assert .Nil (t , rcvMsg .GetStringProperty ("nonExistentProperty" ))
115
+ assert .Nil (t , rcvMsg .GetStringProperty (unsetPropName ))
116
+
95
117
}
96
118
97
119
/*
@@ -117,7 +139,7 @@ func TestStringPropertyTextMessageNilBody(t *testing.T) {
117
139
118
140
propName := "myProperty2"
119
141
propValue := "myValue2"
120
- retErr := msg .SetStringProperty (propName , propValue )
142
+ retErr := msg .SetStringProperty (propName , & propValue )
121
143
assert .Nil (t , retErr )
122
144
123
145
// Now send the message and get it back again, to check that it roundtripped.
@@ -172,12 +194,12 @@ func TestStringPropertyTextMessageEmptyBody(t *testing.T) {
172
194
173
195
propAName := "myPropertyA"
174
196
propAValue := "myValueA"
175
- retErr := msg .SetStringProperty (propAName , propAValue )
197
+ retErr := msg .SetStringProperty (propAName , & propAValue )
176
198
assert .Nil (t , retErr )
177
199
178
200
propBName := "myPropertyB"
179
201
propBValue := "myValueB"
180
- retErr = msg .SetStringProperty (propBName , propBValue )
202
+ retErr = msg .SetStringProperty (propBName , & propBValue )
181
203
assert .Nil (t , retErr )
182
204
183
205
// Now send the message and get it back again.
0 commit comments