@@ -350,29 +350,128 @@ func Test_PublishServiceError(t *testing.T) {
350350func Test_processRevision (t * testing.T ) {
351351 client , httpClient := GetTestServiceClient ()
352352
353- // tests for updating existing revision
354- httpClient .SetResponses ([]api.MockResponse {
355- {
356- FileName : "./testdata/servicerevision.json" , // for call to update the serviceRevision
357- RespCode : http .StatusOK ,
353+ testCases := map [string ]struct {
354+ skip bool
355+ httpResponses []api.MockResponse
356+ serviceBody ServiceBody
357+ expectedRevName string
358+ }{
359+ "publish new revision" : {
360+ httpResponses : []api.MockResponse {
361+ {
362+ FileName : "./testdata/servicerevision.json" , // for call to update the serviceRevision
363+ RespCode : http .StatusOK ,
364+ },
365+ {
366+ FileName : "./testdata/servicerevision.json" , // for call to update the serviceRevision x-agent-details
367+ RespCode : http .StatusOK ,
368+ },
369+ {
370+ FileName : "./testdata/servicerevision.json" , // for call to update the serviceRevision
371+ RespCode : http .StatusOK ,
372+ },
373+ {
374+ FileName : "./testdata/servicerevision.json" , // for call to update the serviceRevision x-agent-details
375+ RespCode : http .StatusOK ,
376+ },
377+ },
378+ serviceBody : ServiceBody {
379+ APIName : "daleapi" ,
380+ Documentation : []byte ("\" docs\" " ),
381+ Image : "abcde" ,
382+ ImageContentType : "image/jpeg" ,
383+ ResourceType : Oas2 ,
384+ RestAPIID : "12345" ,
385+ },
386+ expectedRevName : "daleapi" ,
358387 },
359- {
360- FileName : "./testdata/servicerevision.json" , // for call to update the serviceRevision x-agent-details
361- RespCode : http .StatusOK ,
388+ "skip publish when no changes" : {
389+ httpResponses : []api.MockResponse {
390+ {
391+ RespData : `[{"name": "daleapi","tags": ["tag1","tag2"]}]` ,
392+ RespCode : http .StatusOK ,
393+ },
394+ },
395+ serviceBody : ServiceBody {
396+ APIName : "daleapi" ,
397+ Documentation : []byte ("\" docs\" " ),
398+ Image : "abcde" ,
399+ ImageContentType : "image/jpeg" ,
400+ ResourceType : Oas2 ,
401+ RestAPIID : "12345" ,
402+ specHash : "abc123" ,
403+ specHashes : map [string ]interface {}{
404+ "abc123" : "daleapi" ,
405+ },
406+ serviceContext : serviceContext {
407+ serviceAction : updateAPI ,
408+ },
409+ },
410+ expectedRevName : "daleapi" ,
362411 },
363- {
364- FileName : "./testdata/servicerevision.json" , // for call to update the serviceRevision
365- RespCode : http .StatusOK ,
412+ "skip publish when previous revision found" : {
413+ httpResponses : []api.MockResponse {
414+ {
415+ RespData : `[{"name": "daleapi","tags": ["tag1","tag2"]},{"name": "daleapi-1","tags": ["tag1","tag2"]}]` ,
416+ RespCode : http .StatusOK ,
417+ },
418+ },
419+ serviceBody : ServiceBody {
420+ APIName : "daleapi" ,
421+ Documentation : []byte ("\" docs\" " ),
422+ Image : "abcde" ,
423+ ImageContentType : "image/jpeg" ,
424+ ResourceType : Oas2 ,
425+ RestAPIID : "12345" ,
426+ specHash : "abc123" ,
427+ specHashes : map [string ]interface {}{
428+ "abc123" : "daleapi-1" ,
429+ },
430+ serviceContext : serviceContext {
431+ serviceAction : updateAPI ,
432+ },
433+ },
434+ expectedRevName : "daleapi-1" ,
366435 },
367- {
368- FileName : "./testdata/servicerevision.json" , // for call to update the serviceRevision x-agent-details
369- RespCode : http .StatusOK ,
436+ "find revision match using original spec hash" : {
437+ httpResponses : []api.MockResponse {
438+ {
439+ RespData : `[{"name": "daleapi","tags": ["tag1","tag2"]},{"name": "daleapi-1","tags": ["tag1","tag2"]}]` ,
440+ RespCode : http .StatusOK ,
441+ },
442+ },
443+ serviceBody : ServiceBody {
444+ APIName : "daleapi" ,
445+ Documentation : []byte ("\" docs\" " ),
446+ Image : "abcde" ,
447+ ImageContentType : "image/jpeg" ,
448+ ResourceType : Oas2 ,
449+ RestAPIID : "12345" ,
450+ specHash : "abc1234" ,
451+ originalSpecHash : "abc123" ,
452+ specHashes : map [string ]interface {}{
453+ "abc123" : "daleapi-1" ,
454+ },
455+ serviceContext : serviceContext {
456+ serviceAction : updateAPI ,
457+ },
458+ },
459+ expectedRevName : "daleapi-1" ,
370460 },
371- })
372- cloneServiceBody := serviceBody
373- // Normal Revision
374- client .processRevision (& cloneServiceBody )
375- assert .NotEqual (t , "" , cloneServiceBody .serviceContext .revisionName )
461+ }
462+ for name , tc := range testCases {
463+ t .Run (name , func (t * testing.T ) {
464+ if tc .skip {
465+ return
466+ }
467+ // tests for updating existing revision
468+ httpClient .SetResponses (tc .httpResponses )
469+
470+ client .processRevision (& tc .serviceBody )
471+ assert .NotEqual (t , "" , tc .serviceBody .serviceContext .revisionName )
472+ assert .Equal (t , tc .expectedRevName , tc .serviceBody .serviceContext .revisionName )
473+ })
474+ }
376475}
377476
378477func TestDeleteServiceByAPIID (t * testing.T ) {
0 commit comments