@@ -9064,3 +9064,107 @@ func (suite *GlideTestSuite) TestZLexCount() {
9064
9064
assert .IsType (t , & errors.RequestError {}, err )
9065
9065
})
9066
9066
}
9067
+
9068
+ func (suite * GlideTestSuite ) TestGeoAdd () {
9069
+ suite .runWithDefaultClients (func (client api.BaseClient ) {
9070
+ t := suite .T ()
9071
+ key1 := "{testKey}:1-" + uuid .New ().String ()
9072
+ key2 := "{testKey}:2-" + uuid .New ().String ()
9073
+
9074
+ // Test basic GEOADD
9075
+ membersToCoordinates := map [string ]options.GeospatialData {
9076
+ "Palermo" : {Longitude : 13.361389 , Latitude : 38.115556 },
9077
+ "Catania" : {Longitude : 15.087269 , Latitude : 37.502669 },
9078
+ }
9079
+
9080
+ result , err := client .GeoAdd (key1 , membersToCoordinates )
9081
+ assert .NoError (t , err )
9082
+ assert .Equal (t , int64 (2 ), result )
9083
+
9084
+ // Test with NX option (only if not exists)
9085
+ membersToCoordinates = map [string ]options.GeospatialData {
9086
+ "Catania" : {Longitude : 15.087269 , Latitude : 39 },
9087
+ }
9088
+ result , err = client .GeoAddWithOptions (
9089
+ key1 ,
9090
+ membersToCoordinates ,
9091
+ * options .NewGeoAddOptions ().SetConditionalChange (options .OnlyIfDoesNotExist ),
9092
+ )
9093
+ assert .NoError (t , err )
9094
+ assert .Equal (t , int64 (0 ), result )
9095
+
9096
+ // Test with XX option (only if exists)
9097
+ result , err = client .GeoAddWithOptions (
9098
+ key1 ,
9099
+ membersToCoordinates ,
9100
+ * options .NewGeoAddOptions ().SetConditionalChange (options .OnlyIfExists ),
9101
+ )
9102
+ assert .NoError (t , err )
9103
+ assert .Equal (t , int64 (0 ), result )
9104
+
9105
+ // Test with CH option (change coordinates)
9106
+ membersToCoordinates = map [string ]options.GeospatialData {
9107
+ "Catania" : {Longitude : 15.087269 , Latitude : 40 },
9108
+ "Tel-Aviv" : {Longitude : 32.0853 , Latitude : 34.7818 },
9109
+ }
9110
+ result , err = client .GeoAddWithOptions (
9111
+ key1 ,
9112
+ membersToCoordinates ,
9113
+ * options .NewGeoAddOptions ().SetChanged (true ),
9114
+ )
9115
+ assert .NoError (t , err )
9116
+ assert .Equal (t , int64 (2 ), result )
9117
+
9118
+ // Test error case with wrong key type
9119
+ _ , err = client .Set (key2 , "bar" )
9120
+ assert .NoError (t , err )
9121
+
9122
+ _ , err = client .GeoAddWithOptions (
9123
+ key2 ,
9124
+ membersToCoordinates ,
9125
+ * options .NewGeoAddOptions ().SetChanged (true ),
9126
+ )
9127
+ assert .Error (t , err )
9128
+ assert .IsType (t , & errors.RequestError {}, err )
9129
+ })
9130
+ }
9131
+
9132
+ func (suite * GlideTestSuite ) TestGeoAdd_InvalidArgs () {
9133
+ suite .runWithDefaultClients (func (client api.BaseClient ) {
9134
+ t := suite .T ()
9135
+ key := "{testKey}:3-" + uuid .New ().String ()
9136
+
9137
+ // Test empty members
9138
+ _ , err := client .GeoAdd (key , map [string ]options.GeospatialData {})
9139
+ assert .Error (t , err )
9140
+ assert .IsType (t , & errors.RequestError {}, err )
9141
+
9142
+ // Test invalid longitude (-181)
9143
+ _ , err = client .GeoAdd (key , map [string ]options.GeospatialData {
9144
+ "Place" : {Longitude : - 181 , Latitude : 0 },
9145
+ })
9146
+ assert .Error (t , err )
9147
+ assert .IsType (t , & errors.RequestError {}, err )
9148
+
9149
+ // Test invalid longitude (181)
9150
+ _ , err = client .GeoAdd (key , map [string ]options.GeospatialData {
9151
+ "Place" : {Longitude : 181 , Latitude : 0 },
9152
+ })
9153
+ assert .Error (t , err )
9154
+ assert .IsType (t , & errors.RequestError {}, err )
9155
+
9156
+ // Test invalid latitude (86)
9157
+ _ , err = client .GeoAdd (key , map [string ]options.GeospatialData {
9158
+ "Place" : {Longitude : 0 , Latitude : 86 },
9159
+ })
9160
+ assert .Error (t , err )
9161
+ assert .IsType (t , & errors.RequestError {}, err )
9162
+
9163
+ // Test invalid latitude (-86)
9164
+ _ , err = client .GeoAdd (key , map [string ]options.GeospatialData {
9165
+ "Place" : {Longitude : 0 , Latitude : - 86 },
9166
+ })
9167
+ assert .Error (t , err )
9168
+ assert .IsType (t , & errors.RequestError {}, err )
9169
+ })
9170
+ }
0 commit comments