@@ -120,21 +120,72 @@ async def test_service_apis(self):
120120 self .assertEqual (name , resp .metadata .name )
121121 self .assertTrue (resp .status )
122122
123- service_manifest ['spec' ]['ports' ] = [
124- {'name' : 'new' ,
125- 'port' : 8080 ,
126- 'protocol' : 'TCP' ,
127- 'targetPort' : 8080 }
128- ]
123+ # strategic merge patch
129124 resp = await api .patch_namespaced_service (
130- body = service_manifest ,
131125 name = name ,
132- namespace = 'default'
126+ namespace = "default" ,
127+ body = {
128+ "spec" : {
129+ "ports" : [
130+ {
131+ "name" : "new" ,
132+ "port" : 8080 ,
133+ "protocol" : "TCP" ,
134+ "targetPort" : 8080 ,
135+ }
136+ ]
137+ }
138+ },
139+ )
140+ self .assertEqual (len (resp .spec .ports ), 2 )
141+ self .assertTrue (resp .status )
142+
143+ # json merge patch
144+ resp = await api .patch_namespaced_service (
145+ name = name ,
146+ namespace = "default" ,
147+ body = {
148+ "spec" : {
149+ "ports" : [
150+ {
151+ "name" : "new2" ,
152+ "port" : 8080 ,
153+ "protocol" : "TCP" ,
154+ "targetPort" : 8080 ,
155+ }
156+ ]
157+ }
158+ },
159+ _content_type = "application/merge-patch+json" ,
133160 )
134- self .assertEqual (2 , len (resp .spec .ports ))
161+ self .assertEqual (len (resp .spec .ports ), 1 )
162+ self .assertEqual (resp .spec .ports [0 ].name , "new2" )
135163 self .assertTrue (resp .status )
136164
137- resp = await api .delete_namespaced_service (name = name , body = {}, namespace = 'default' )
165+ # json patch
166+ resp = await api .patch_namespaced_service (
167+ name = name ,
168+ namespace = "default" ,
169+ body = [
170+ {
171+ "op" : "add" ,
172+ "path" : "/spec/ports/0" ,
173+ "value" : {
174+ "name" : "new3" ,
175+ "protocol" : "TCP" ,
176+ "port" : 1000 ,
177+ "targetPort" : 1000 ,
178+ },
179+ }
180+ ],
181+ )
182+ self .assertEqual (len (resp .spec .ports ), 2 )
183+ self .assertEqual (resp .spec .ports [0 ].name , "new3" )
184+ self .assertEqual (resp .spec .ports [1 ].name , "new2" )
185+ self .assertTrue (resp .status )
186+ resp = await api .delete_namespaced_service (
187+ name = name , body = {}, namespace = "default"
188+ )
138189
139190 async def test_replication_controller_apis (self ):
140191 client = api_client .ApiClient (configuration = self .config )
@@ -207,9 +258,15 @@ async def test_configmap_apis(self):
207258 name = name , namespace = 'default' )
208259 self .assertEqual (name , resp .metadata .name )
209260
210- test_configmap [ 'data' ][ 'config.json' ] = "{}"
261+ # strategic merge patch
211262 resp = await api .patch_namespaced_config_map (
212- name = name , namespace = 'default' , body = test_configmap )
263+ name = name , namespace = 'default' , body = {'data' : {'key' : 'value' , 'frontend.cnf' : 'patched' }})
264+
265+ resp = await api .read_namespaced_config_map (
266+ name = name , namespace = 'default' )
267+ self .assertEqual (resp .data ['config.json' ], test_configmap ['data' ]['config.json' ])
268+ self .assertEqual (resp .data ['frontend.cnf' ], 'patched' )
269+ self .assertEqual (resp .data ['key' ], 'value' )
213270
214271 resp = await api .delete_namespaced_config_map (
215272 name = name , body = {}, namespace = 'default' )
0 commit comments