@@ -56,16 +56,31 @@ func TestStringPropertyTextMsg(t *testing.T) {
5656 propValue := "myValue"
5757
5858 // 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 ))
6260
6361 // Test the ability to set properties before the message is sent.
64- retErr := txtMsg .SetStringProperty (propName , propValue )
62+ retErr := txtMsg .SetStringProperty (propName , & propValue )
6563 assert .Nil (t , retErr )
6664 assert .Equal (t , propValue , * txtMsg .GetStringProperty (propName ))
6765 assert .Equal (t , msgBody , * txtMsg .GetText ())
6866
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+
6984 // Set up objects for send/receive
7085 queue := context .CreateQueue ("DEV.QUEUE.1" )
7186 consumer , errCons := context .CreateConsumer (queue )
@@ -92,6 +107,13 @@ func TestStringPropertyTextMsg(t *testing.T) {
92107 // Check property is available on received message.
93108 assert .Equal (t , propValue , * rcvMsg .GetStringProperty (propName ))
94109
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+
95117}
96118
97119/*
@@ -117,7 +139,7 @@ func TestStringPropertyTextMessageNilBody(t *testing.T) {
117139
118140 propName := "myProperty2"
119141 propValue := "myValue2"
120- retErr := msg .SetStringProperty (propName , propValue )
142+ retErr := msg .SetStringProperty (propName , & propValue )
121143 assert .Nil (t , retErr )
122144
123145 // Now send the message and get it back again, to check that it roundtripped.
@@ -172,12 +194,12 @@ func TestStringPropertyTextMessageEmptyBody(t *testing.T) {
172194
173195 propAName := "myPropertyA"
174196 propAValue := "myValueA"
175- retErr := msg .SetStringProperty (propAName , propAValue )
197+ retErr := msg .SetStringProperty (propAName , & propAValue )
176198 assert .Nil (t , retErr )
177199
178200 propBName := "myPropertyB"
179201 propBValue := "myValueB"
180- retErr = msg .SetStringProperty (propBName , propBValue )
202+ retErr = msg .SetStringProperty (propBName , & propBValue )
181203 assert .Nil (t , retErr )
182204
183205 // Now send the message and get it back again.
0 commit comments