github.com/xgoffin/jenkins-library@v1.154.0/cmd/gctsExecuteABAPQualityChecks_test.go (about) 1 package cmd 2 3 import ( 4 "bytes" 5 "encoding/xml" 6 "io" 7 "io/ioutil" 8 "net/http" 9 "testing" 10 11 piperhttp "github.com/SAP/jenkins-library/pkg/http" 12 "github.com/pkg/errors" 13 "github.com/stretchr/testify/assert" 14 ) 15 16 func TestDiscoverServerSuccess(t *testing.T) { 17 18 config := gctsExecuteABAPQualityChecksOptions{ 19 Host: "http://testHost.com:50000", 20 Client: "000", 21 Repository: "testRepo", 22 Username: "testUser", 23 Password: "testPassword", 24 Scope: "localChangedObjects", 25 Commit: "0123456789abcdefghijkl", 26 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 27 } 28 29 t.Run("discover server successful", func(t *testing.T) { 30 31 httpClient := httpMockGcts{ 32 StatusCode: 200, 33 Header: map[string][]string{"x-csrf-token": {"ZegUEgfa50R7ZfGGxOtx2A=="}}, 34 ResponseBody: ` 35 <?xml version="1.0" encoding="utf-8"?> 36 <app:service xmlns:app="http://www.w3.org/2007/app" xmlns:atom="http://www.w3.org/2005/Atom"/> 37 `} 38 39 header, err := discoverServer(&config, &httpClient) 40 41 if assert.NoError(t, err) { 42 43 t.Run("check url", func(t *testing.T) { 44 assert.Equal(t, "http://testHost.com:50000/sap/bc/adt/core/discovery?sap-client=000", httpClient.URL) 45 }) 46 47 t.Run("check method", func(t *testing.T) { 48 assert.Equal(t, "GET", httpClient.Method) 49 }) 50 51 t.Run("check header", func(t *testing.T) { 52 assert.Equal(t, http.Header{"x-csrf-token": []string{"ZegUEgfa50R7ZfGGxOtx2A=="}}, *header) 53 }) 54 55 } 56 57 }) 58 } 59 60 func TestDiscoverServerFailure(t *testing.T) { 61 62 config := gctsExecuteABAPQualityChecksOptions{ 63 Host: "http://testHost3.com:50000", 64 Client: "000", 65 Repository: "testRepo", 66 Username: "testUser", 67 Password: "testPassword", 68 Scope: "localChangedObjects", 69 Commit: "0123456789abcdefghijkl", 70 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 71 } 72 73 t.Run("a http error occurred", func(t *testing.T) { 74 75 httpClient := httpMockGctsT{StatusCode: 403, ResponseBody: ` 76 <html> 77 <head> 78 <meta http-equiv="content-type" content="text/html; charset=windows-1252"> 79 <title>Service cannot be reached</title> 80 <style> 81 body { 82 background: #ffffff; 83 text-align: center; 84 width: 100%; 85 height: 100%; 86 overflow: hidden; 87 } 88 </style> 89 </head> 90 91 <body> 92 <div class="content"> 93 <div class="valigned"> 94 <p class="centerText"><span class="errorTextHeader"> 403 Forbidden </span></p> 95 </div> 96 </div> 97 <div class="footer"> 98 <div class="footerLeft"></div> 99 <div class="footerRight"> 100 <p class="bottomText"><span class="biggerBottomText">©</span>2020 SAP SE, All rights reserved.</p> 101 </div> 102 </div> 103 </body> 104 </html> 105 `} 106 107 header, err := discoverServer(&config, &httpClient) 108 109 t.Run("check error", func(t *testing.T) { 110 assert.EqualError(t, err, "discovery of the ABAP server failed: a http error occurred") 111 }) 112 113 t.Run("check header", func(t *testing.T) { 114 assert.Equal(t, (*http.Header)(nil), header) 115 }) 116 117 }) 118 119 t.Run("discovery response is nil", func(t *testing.T) { 120 121 httpClient := httpMockGctsT{StatusCode: 200, ResponseBody: ``} 122 123 header, err := discoverServer(&config, &httpClient) 124 125 t.Run("check error", func(t *testing.T) { 126 assert.EqualError(t, err, "discovery of the ABAP server failed: did not retrieve a HTTP response") 127 }) 128 129 t.Run("check header", func(t *testing.T) { 130 assert.Equal(t, (*http.Header)(nil), header) 131 }) 132 133 }) 134 135 t.Run("discovery header is nil", func(t *testing.T) { 136 137 httpClient := httpMockGctsT{ 138 StatusCode: 200, 139 Header: nil, 140 ResponseBody: ` 141 <?xml version="1.0" encoding="utf-8"?> 142 <app:service xmlns:app="http://www.w3.org/2007/app" xmlns:atom="http://www.w3.org/2005/Atom"/> 143 `} 144 145 header, err := discoverServer(&config, &httpClient) 146 147 t.Run("check error", func(t *testing.T) { 148 assert.EqualError(t, err, "discovery of the ABAP server failed: did not retrieve a HTTP response") 149 }) 150 151 t.Run("check header", func(t *testing.T) { 152 assert.Equal(t, (*http.Header)(nil), header) 153 }) 154 155 }) 156 } 157 158 func TestGetLocalObjectsSuccess(t *testing.T) { 159 160 t.Run("return multiple objects successfully", func(t *testing.T) { 161 162 config := gctsExecuteABAPQualityChecksOptions{ 163 Host: "http://testHost.com:50000", 164 Client: "000", 165 Repository: "testRepo", 166 Username: "testUser", 167 Password: "testPassword", 168 Commit: "0123456789abcdefghijkl", 169 Scope: "localChangedObjects", 170 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 171 } 172 173 httpClient := httpMockGctsT{StatusCode: 200} 174 175 object1 := repoObject{ 176 177 Object: "ZCL_GCTS", 178 Type: "CLAS", 179 } 180 object2 := repoObject{ 181 182 Object: "ZP_GCTS", 183 Type: "DEVC", 184 } 185 object3 := repoObject{ 186 187 Object: "ZIF_GCTS_API", 188 Type: "INTF", 189 } 190 var repoObjects []repoObject 191 repoObjects = append(repoObjects, object1) 192 repoObjects = append(repoObjects, object2) 193 repoObjects = append(repoObjects, object3) 194 195 objects, err := getLocalObjects(&config, &httpClient) 196 197 if assert.NoError(t, err) { 198 199 t.Run("check url", func(t *testing.T) { 200 assert.Equal(t, "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo/compareCommits?fromCommit=xyz987654321&toCommit=0123456789abcdefghijkl&sap-client=000", httpClient.URL) 201 }) 202 203 t.Run("check method", func(t *testing.T) { 204 assert.Equal(t, "GET", httpClient.Method) 205 }) 206 207 t.Run("check package objects", func(t *testing.T) { 208 assert.Equal(t, repoObjects, objects) 209 }) 210 211 } 212 213 }) 214 215 t.Run("no objects returned by http call", func(t *testing.T) { 216 217 config := gctsExecuteABAPQualityChecksOptions{ 218 Host: "http://testHost.com:50000", 219 Client: "000", 220 Repository: "testRepo2", 221 Username: "testUser", 222 Password: "testPassword", 223 Commit: "0123456789abcdefghijkl", 224 Scope: "localChangedObjects", 225 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 226 } 227 228 var repoObjects []repoObject 229 230 httpClient := httpMockGctsT{StatusCode: 200, ResponseBody: `{}`} 231 232 objects, err := getLocalObjects(&config, &httpClient) 233 234 if assert.NoError(t, err) { 235 236 t.Run("check url", func(t *testing.T) { 237 assert.Equal(t, "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo2/compareCommits?fromCommit=xyz987654321&toCommit=0123456789abcdefghijkl&sap-client=000", httpClient.URL) 238 }) 239 240 t.Run("check method", func(t *testing.T) { 241 assert.Equal(t, "GET", httpClient.Method) 242 }) 243 244 t.Run("check package objects", func(t *testing.T) { 245 assert.Equal(t, repoObjects, objects) 246 }) 247 } 248 249 }) 250 } 251 252 func TestGetLocalObjectsFailure(t *testing.T) { 253 254 config := gctsExecuteABAPQualityChecksOptions{ 255 Host: "http://testHost.com:50000", 256 Client: "000", 257 Repository: "testRepo", 258 Username: "testUser", 259 Password: "testPassword", 260 Commit: "0123456789abcdefghijkl", 261 Scope: "localChangedObjects", 262 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 263 } 264 265 t.Run("http error occurred", func(t *testing.T) { 266 267 httpClient := httpMockGcts{StatusCode: 500, ResponseBody: ` 268 { 269 "exception": "No relation between system and repository" 270 } 271 `} 272 273 _, err := getLocalObjects(&config, &httpClient) 274 275 assert.EqualError(t, err, "get local changed objects failed: get history failed: a http error occurred") 276 }) 277 } 278 279 func TestGetRemoteObjectsSuccess(t *testing.T) { 280 281 config := gctsExecuteABAPQualityChecksOptions{ 282 Host: "http://testHost.com:50000", 283 Client: "000", 284 Repository: "testRepo", 285 Username: "testUser", 286 Password: "testPassword", 287 Commit: "0123456789abcdefghijkl", 288 Scope: "remoteChangedObjects", 289 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 290 } 291 292 t.Run("return multiple objects successfully", func(t *testing.T) { 293 294 httpClient := httpMockGctsT{StatusCode: 200} 295 296 object1 := repoObject{ 297 298 Object: "ZCL_GCTS", 299 Type: "CLAS", 300 } 301 object2 := repoObject{ 302 303 Object: "ZP_GCTS", 304 Type: "DEVC", 305 } 306 object3 := repoObject{ 307 308 Object: "ZIF_GCTS_API", 309 Type: "INTF", 310 } 311 var repoObjects []repoObject 312 repoObjects = append(repoObjects, object1) 313 repoObjects = append(repoObjects, object2) 314 repoObjects = append(repoObjects, object3) 315 316 objects, err := getRemoteObjects(&config, &httpClient) 317 318 if assert.NoError(t, err) { 319 320 t.Run("check url", func(t *testing.T) { 321 assert.Equal(t, "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo/compareCommits?fromCommit=7845abaujztrw785&toCommit=0123456789abcdefghijkl&sap-client=000", httpClient.URL) 322 }) 323 324 t.Run("check method", func(t *testing.T) { 325 assert.Equal(t, "GET", httpClient.Method) 326 }) 327 328 t.Run("check package objects", func(t *testing.T) { 329 assert.Equal(t, repoObjects, objects) 330 }) 331 332 } 333 334 }) 335 336 t.Run("no objects returned by http call", func(t *testing.T) { 337 338 config := gctsExecuteABAPQualityChecksOptions{ 339 Host: "http://testHost.com:50000", 340 Client: "000", 341 Repository: "testRepo2", 342 Username: "testUser", 343 Password: "testPassword", 344 Commit: "0123456789abcdefghijkl", 345 Scope: "remoteChangedObjects", 346 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 347 } 348 httpClient := httpMockGctsT{StatusCode: 200, ResponseBody: `{}`} 349 var repoObjects []repoObject 350 objects, err := getRemoteObjects(&config, &httpClient) 351 352 if assert.NoError(t, err) { 353 354 t.Run("check url", func(t *testing.T) { 355 assert.Equal(t, "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo2/compareCommits?fromCommit=7845abaujztrw785&toCommit=0123456789abcdefghijkl&sap-client=000", httpClient.URL) 356 }) 357 358 t.Run("check method", func(t *testing.T) { 359 assert.Equal(t, "GET", httpClient.Method) 360 }) 361 362 t.Run("check package objects", func(t *testing.T) { 363 assert.Equal(t, repoObjects, objects) 364 }) 365 } 366 367 }) 368 } 369 370 func TestGetRemoteObjectsFailure(t *testing.T) { 371 372 config := gctsExecuteABAPQualityChecksOptions{ 373 Host: "http://testHost.com:50000", 374 Client: "000", 375 Repository: "testRepo", 376 Username: "testUser", 377 Password: "testPassword", 378 Commit: "0123456789abcdefghijkl", 379 Scope: "remoteChangedObjects", 380 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 381 } 382 383 t.Run("http error occurred", func(t *testing.T) { 384 385 httpClient := httpMockGcts{StatusCode: 500, ResponseBody: ` 386 { 387 "exception": "No relation between system and repository" 388 } 389 `} 390 391 _, err := getRemoteObjects(&config, &httpClient) 392 393 assert.EqualError(t, err, "get remote changed objects failed: get repository history failed: a http error occurred") 394 }) 395 } 396 397 func TestGetLocalPackagesSuccess(t *testing.T) { 398 399 config := gctsExecuteABAPQualityChecksOptions{ 400 Host: "http://testHost.com:50000", 401 Client: "000", 402 Repository: "testRepo", 403 Username: "testUser", 404 Password: "testPassword", 405 Commit: "0123456789abcdefghijkl", 406 Scope: "localChangedPackages", 407 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 408 } 409 410 t.Run("return multiple objects successfully", func(t *testing.T) { 411 412 httpClient := httpMockGctsT{StatusCode: 200} 413 414 object1 := repoObject{ 415 416 Object: "SGCTS", 417 418 Type: "DEVC", 419 } 420 object2 := repoObject{ 421 422 Object: "SGCTS_2", 423 Type: "DEVC", 424 } 425 426 var repoObjects []repoObject 427 repoObjects = append(repoObjects, object1) 428 repoObjects = append(repoObjects, object2) 429 430 objects, err := getLocalPackages(&config, &httpClient) 431 432 if assert.NoError(t, err) { 433 434 t.Run("check url", func(t *testing.T) { 435 assert.Equal(t, "http://testHost.com:50000/sap/bc/cts_abapvcs/objects/INTF/ZIF_GCTS_API?sap-client=000", httpClient.URL) 436 }) 437 438 t.Run("check method", func(t *testing.T) { 439 assert.Equal(t, "GET", httpClient.Method) 440 }) 441 442 t.Run("check package objects", func(t *testing.T) { 443 assert.Equal(t, repoObjects, objects) 444 }) 445 446 } 447 448 }) 449 450 t.Run("no objects returned by http call", func(t *testing.T) { 451 452 config := gctsExecuteABAPQualityChecksOptions{ 453 Host: "http://testHost.com:50000", 454 Client: "000", 455 Repository: "testRepo2", 456 Username: "testUser", 457 Password: "testPassword", 458 Commit: "0123456789abcdefghijkl", 459 Scope: "localChangedObjects", 460 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 461 } 462 463 httpClient := httpMockGctsT{StatusCode: 200, ResponseBody: `{}`} 464 var repoObjects []repoObject 465 objects, err := getLocalPackages(&config, &httpClient) 466 467 if assert.NoError(t, err) { 468 469 t.Run("check url", func(t *testing.T) { 470 assert.Equal(t, "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo2/compareCommits?fromCommit=xyz987654321&toCommit=0123456789abcdefghijkl&sap-client=000", httpClient.URL) 471 }) 472 473 t.Run("check method", func(t *testing.T) { 474 assert.Equal(t, "GET", httpClient.Method) 475 }) 476 477 t.Run("check package objects", func(t *testing.T) { 478 assert.Equal(t, repoObjects, objects) 479 }) 480 } 481 482 }) 483 } 484 485 func TestGetLocalPackagesFailure(t *testing.T) { 486 487 config := gctsExecuteABAPQualityChecksOptions{ 488 Host: "http://testHost.com:50000", 489 Client: "000", 490 Repository: "testRepo", 491 Username: "testUser", 492 Password: "testPassword", 493 Commit: "0123456789abcdefghijkl", 494 Scope: "localChangedPackages", 495 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 496 } 497 t.Run("http error occurred", func(t *testing.T) { 498 499 httpClient := httpMockGctsT{StatusCode: 500, ResponseBody: ` 500 { 501 "exception": "No relation between system and repository" 502 } 503 `} 504 505 _, err := getLocalPackages(&config, &httpClient) 506 507 assert.EqualError(t, err, "get local changed objects failed: get history failed: a http error occurred") 508 }) 509 } 510 511 func TestGetRemotePackagesSuccess(t *testing.T) { 512 513 config := gctsExecuteABAPQualityChecksOptions{ 514 Host: "http://testHost.com:50000", 515 Client: "000", 516 Repository: "testRepo", 517 Username: "testUser", 518 Password: "testPassword", 519 Commit: "0123456789abcdefghijkl", 520 Scope: "remoteChangedPackages", 521 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 522 } 523 524 t.Run("return multiple objects successfully", func(t *testing.T) { 525 526 httpClient := httpMockGctsT{StatusCode: 200} 527 528 object1 := repoObject{ 529 530 Object: "SGCTS", 531 532 Type: "DEVC", 533 } 534 object2 := repoObject{ 535 536 Object: "SGCTS_2", 537 Type: "DEVC", 538 } 539 var repoObjects []repoObject 540 repoObjects = append(repoObjects, object1) 541 repoObjects = append(repoObjects, object2) 542 543 objects, err := getRemotePackages(&config, &httpClient) 544 545 if assert.NoError(t, err) { 546 547 t.Run("check url", func(t *testing.T) { 548 assert.Equal(t, "http://testHost.com:50000/sap/bc/cts_abapvcs/objects/INTF/ZIF_GCTS_API?sap-client=000", httpClient.URL) 549 }) 550 551 t.Run("check method", func(t *testing.T) { 552 assert.Equal(t, "GET", httpClient.Method) 553 }) 554 555 t.Run("check package objects", func(t *testing.T) { 556 assert.Equal(t, repoObjects, objects) 557 }) 558 559 } 560 561 }) 562 563 t.Run("no objects returned by http call", func(t *testing.T) { 564 565 config := gctsExecuteABAPQualityChecksOptions{ 566 Host: "http://testHost.com:50000", 567 Client: "000", 568 Repository: "testRepo2", 569 Username: "testUser", 570 Password: "testPassword", 571 Commit: "0123456789abcdefghijkl", 572 Scope: "remoteChangedPackages", 573 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 574 } 575 576 httpClient := httpMockGctsT{StatusCode: 200, ResponseBody: `{}`} 577 var repoObjects []repoObject 578 objects, err := getRemoteObjects(&config, &httpClient) 579 580 if assert.NoError(t, err) { 581 582 t.Run("check url", func(t *testing.T) { 583 assert.Equal(t, "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo2/compareCommits?fromCommit=7845abaujztrw785&toCommit=0123456789abcdefghijkl&sap-client=000", httpClient.URL) 584 }) 585 586 t.Run("check method", func(t *testing.T) { 587 assert.Equal(t, "GET", httpClient.Method) 588 }) 589 590 t.Run("check package objects", func(t *testing.T) { 591 assert.Equal(t, repoObjects, objects) 592 }) 593 } 594 595 }) 596 } 597 598 func TestGetRemotePackagesFailure(t *testing.T) { 599 600 config := gctsExecuteABAPQualityChecksOptions{ 601 Host: "http://testHost.com:50000", 602 Client: "000", 603 Repository: "testRepo", 604 Username: "testUser", 605 Password: "testPassword", 606 Commit: "0123456789abcdefghijkl", 607 Scope: "remoteChangedPackages", 608 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 609 } 610 t.Run("http error occurred", func(t *testing.T) { 611 612 httpClient := httpMockGctsT{StatusCode: 500, ResponseBody: ` 613 { 614 "exception": "No relation between system and repository" 615 } 616 `} 617 618 _, err := getRemotePackages(&config, &httpClient) 619 620 assert.EqualError(t, err, "get remote changed packages failed: get repository history failed: a http error occurred") 621 }) 622 } 623 624 func TestGetPackagesSuccess(t *testing.T) { 625 626 config := gctsExecuteABAPQualityChecksOptions{ 627 Host: "http://testHost.com:50000", 628 Client: "000", 629 Repository: "testRepo", 630 Username: "testUser", 631 Password: "testPassword", 632 Commit: "0123456789abcdefghijkl", 633 Scope: "packages", 634 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 635 } 636 637 t.Run("return multiple objects successfully", func(t *testing.T) { 638 639 httpClient := httpMockGctsT{StatusCode: 200} 640 641 object1 := repoObject{ 642 643 Pgmid: "R3TR", 644 Object: "ZP_GCTS", 645 Type: "DEVC", 646 Description: "Package(ABAP Objects)", 647 } 648 649 var repoObjects []repoObject 650 repoObjects = append(repoObjects, object1) 651 652 objects, err := getPackages(&config, &httpClient) 653 654 if assert.NoError(t, err) { 655 656 t.Run("check url", func(t *testing.T) { 657 assert.Equal(t, "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo/objects?sap-client=000", httpClient.URL) 658 }) 659 660 t.Run("check method", func(t *testing.T) { 661 assert.Equal(t, "GET", httpClient.Method) 662 }) 663 664 t.Run("check package objects", func(t *testing.T) { 665 assert.Equal(t, repoObjects, objects) 666 }) 667 668 } 669 670 }) 671 672 t.Run("no objects returned by http call", func(t *testing.T) { 673 674 config := gctsExecuteABAPQualityChecksOptions{ 675 Host: "http://testHost.com:50000", 676 Client: "000", 677 Repository: "testRepo2", 678 Username: "testUser", 679 Password: "testPassword", 680 Commit: "0123456789abcdefghijkl", 681 Scope: "packages", 682 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 683 } 684 685 httpClient := httpMockGcts{StatusCode: 200, ResponseBody: `{}`} 686 var repoObjects []repoObject 687 objects, err := getPackages(&config, &httpClient) 688 689 if assert.NoError(t, err) { 690 691 t.Run("check url", func(t *testing.T) { 692 assert.Equal(t, "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo2/objects?sap-client=000", httpClient.URL) 693 }) 694 695 t.Run("check method", func(t *testing.T) { 696 assert.Equal(t, "GET", httpClient.Method) 697 }) 698 699 t.Run("check package objects", func(t *testing.T) { 700 assert.Equal(t, repoObjects, objects) 701 }) 702 } 703 704 }) 705 } 706 707 func TestGetPackagesFailure(t *testing.T) { 708 709 config := gctsExecuteABAPQualityChecksOptions{ 710 Host: "http://testHost.com:50000", 711 Client: "000", 712 Repository: "testRepo2", 713 Username: "testUser", 714 Password: "testPassword", 715 Commit: "0123456789abcdefghijkl", 716 Scope: "packages", 717 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 718 } 719 t.Run("http error occurred", func(t *testing.T) { 720 721 httpClient := httpMockGctsT{StatusCode: 500, ResponseBody: ` 722 { 723 "exception": "No relation between system and repository" 724 } 725 `} 726 727 _, err := getPackages(&config, &httpClient) 728 729 assert.EqualError(t, err, "get packages failed: could not get repository objects: a http error occurred") 730 }) 731 } 732 733 func TestGetRepositoryObjectsSuccess(t *testing.T) { 734 735 config := gctsExecuteABAPQualityChecksOptions{ 736 Host: "http://testHost.com:50000", 737 Client: "000", 738 Repository: "testRepo", 739 Username: "testUser", 740 Password: "testPassword", 741 Commit: "0123456789abcdefghijkl", 742 Scope: "repository", 743 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 744 } 745 746 t.Run("return multiple objects successfully", func(t *testing.T) { 747 748 httpClient := httpMockGctsT{StatusCode: 200} 749 750 object1 := repoObject{ 751 Pgmid: "R3TR", 752 Object: "ZCL_GCTS", 753 Type: "CLAS", 754 Description: "Class (ABAP Objects)", 755 } 756 757 object3 := repoObject{ 758 Pgmid: "R3TR", 759 Object: "ZIF_GCTS_API", 760 Type: "INTF", 761 Description: "Interface (ABAP Objects)", 762 } 763 var repoObjects []repoObject 764 repoObjects = append(repoObjects, object1) 765 repoObjects = append(repoObjects, object3) 766 767 objects, err := getRepositoryObjects(&config, &httpClient) 768 769 if assert.NoError(t, err) { 770 771 t.Run("check url", func(t *testing.T) { 772 assert.Equal(t, "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo/objects?sap-client=000", httpClient.URL) 773 }) 774 775 t.Run("check method", func(t *testing.T) { 776 assert.Equal(t, "GET", httpClient.Method) 777 }) 778 779 t.Run("check package objects", func(t *testing.T) { 780 assert.Equal(t, repoObjects, objects) 781 }) 782 783 } 784 785 }) 786 787 t.Run("no objects returned by http call", func(t *testing.T) { 788 789 config := gctsExecuteABAPQualityChecksOptions{ 790 Host: "http://testHost.com:50000", 791 Client: "000", 792 Repository: "testRepo2", 793 Username: "testUser", 794 Password: "testPassword", 795 Commit: "0123456789abcdefghijkl", 796 Scope: "repository", 797 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 798 } 799 800 httpClient := httpMockGctsT{StatusCode: 200, ResponseBody: `{}`} 801 var repoObjects []repoObject 802 objects, err := getRepositoryObjects(&config, &httpClient) 803 804 if assert.NoError(t, err) { 805 806 t.Run("check url", func(t *testing.T) { 807 assert.Equal(t, "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo2/objects?sap-client=000", httpClient.URL) 808 }) 809 810 t.Run("check method", func(t *testing.T) { 811 assert.Equal(t, "GET", httpClient.Method) 812 }) 813 814 t.Run("check package objects", func(t *testing.T) { 815 assert.Equal(t, repoObjects, objects) 816 }) 817 } 818 819 }) 820 } 821 822 func TestGetRepositoryObjectsFailure(t *testing.T) { 823 824 config := gctsExecuteABAPQualityChecksOptions{ 825 Host: "http://testHost.com:50000", 826 Client: "000", 827 Repository: "testRepo", 828 Username: "testUser", 829 Password: "testPassword", 830 Commit: "0123456789abcdefghijkl", 831 Scope: "repository", 832 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 833 } 834 835 t.Run("http error occurred", func(t *testing.T) { 836 837 httpClient := httpMockGctsT{StatusCode: 500, ResponseBody: ` 838 { 839 "exception": "No relation between system and repository" 840 } 841 `} 842 843 _, err := getRepositoryObjects(&config, &httpClient) 844 845 assert.EqualError(t, err, "could not get repository objects: a http error occurred") 846 }) 847 } 848 849 func TestExecuteAUnitTestSuccess(t *testing.T) { 850 851 config := gctsExecuteABAPQualityChecksOptions{ 852 Host: "http://testHost.com:50000", 853 Client: "000", 854 Repository: "testRepo", 855 Username: "testUser", 856 Password: "testPassword", 857 Commit: "0123456789abcdefghijkl", 858 Scope: "repository", 859 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 860 AtcResultsFileName: "ATCResults.xml", 861 AUnitResultsFileName: "AUnitResults.xml", 862 } 863 864 t.Run("all unit tests were successful", func(t *testing.T) { 865 866 httpClient := httpMockGctsT{StatusCode: 200} 867 868 object := repoObject{ 869 Pgmid: "R3TR", 870 Object: "ZCL_GCTS", 871 Type: "CLAS", 872 Description: "Clas Object", 873 } 874 875 var repoObjects []repoObject 876 repoObjects = append(repoObjects, object) 877 878 err := executeAUnitTest(&config, &httpClient, repoObjects) 879 880 if assert.NoError(t, err) { 881 882 t.Run("check url", func(t *testing.T) { 883 assert.Equal(t, "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo?sap-client=000", httpClient.URL) 884 }) 885 886 t.Run("check method", func(t *testing.T) { 887 assert.Equal(t, "GET", httpClient.Method) 888 }) 889 890 } 891 }) 892 893 t.Run("no unit tests found", func(t *testing.T) { 894 895 httpClient := httpMockGctsT{StatusCode: 200, ResponseBody: ` 896 <?xml version="1.0" encoding="utf-8"?> 897 <aunit:runResult xmlns:aunit="http://www.sap.com/adt/aunit"> 898 <alerts> 899 <alert kind="noTestClasses" severity="tolerable"> 900 <title>The task definition does not refer to any test</title> 901 </alert> 902 </alerts> 903 </aunit:runResult> 904 `} 905 object := repoObject{ 906 Pgmid: "R3TR", 907 Object: "ZP_NON_EXISTANT", 908 Type: "CLAS", 909 Description: "Clas Object", 910 } 911 912 var repoObjects []repoObject 913 repoObjects = append(repoObjects, object) 914 err := executeAUnitTest(&config, &httpClient, repoObjects) 915 916 if assert.NoError(t, err) { 917 918 t.Run("check url", func(t *testing.T) { 919 assert.Equal(t, "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo?sap-client=000", httpClient.URL) 920 }) 921 922 t.Run("check method", func(t *testing.T) { 923 assert.Equal(t, "GET", httpClient.Method) 924 }) 925 926 } 927 }) 928 } 929 930 func TestExecuteAUnitTestFailure(t *testing.T) { 931 932 config := gctsExecuteABAPQualityChecksOptions{ 933 Host: "http://testHost.com:50000", 934 Client: "000", 935 Repository: "testRepo", 936 Username: "testUser", 937 Password: "testPassword", 938 Commit: "0123456789abcdefghijkl", 939 Scope: "repository", 940 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 941 AtcResultsFileName: "ATCResults.xml", 942 AUnitResultsFileName: "AUnitResults.xml", 943 } 944 945 var repoObjects []repoObject 946 947 t.Run("a http error occurred", func(t *testing.T) { 948 949 httpClient := httpMockGctsT{StatusCode: 403, ResponseBody: ` 950 CSRF token validation failed 951 `} 952 953 header := make(http.Header) 954 header.Add("Accept", "application/atomsvc+xml") 955 header.Add("x-csrf-token", "ZegUEgfa50R7ZfGGxOtx2A==") 956 header.Add("saml2", "disabled") 957 958 err := executeAUnitTest(&config, &httpClient, repoObjects) 959 960 assert.EqualError(t, err, "execute of Aunit test has failed: run of unit tests failed: discovery of the ABAP server failed: a http error occurred") 961 962 }) 963 } 964 965 func TestExecuteATCCheckSuccess(t *testing.T) { 966 967 config := gctsExecuteABAPQualityChecksOptions{ 968 Host: "http://testHost.com:50000", 969 Client: "000", 970 Repository: "testRepo", 971 Username: "testUser", 972 Password: "testPassword", 973 Commit: "0123456789abcdefghijkl", 974 AtcVariant: "DEFAULT_REMOTE_REF", 975 Scope: "repository", 976 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 977 AtcResultsFileName: "ATCResults.xml", 978 } 979 980 header := make(http.Header) 981 header.Add("Accept", "application/atomsvc+xml") 982 header.Add("x-csrf-token", "ZegUEgfa50R7ZfGGxOtx2A==") 983 header.Add("saml2", "disabled") 984 985 t.Run("atc checks were found", func(t *testing.T) { 986 987 httpClient := httpMockGctsT{StatusCode: 200} 988 989 object := repoObject{ 990 Pgmid: "R3TR", 991 Object: "ZCL_GCTS", 992 Type: "CLAS", 993 Description: "Clas Object", 994 } 995 996 var repoObjects []repoObject 997 repoObjects = append(repoObjects, object) 998 999 err := executeATCCheck(&config, &httpClient, repoObjects) 1000 1001 if assert.NoError(t, err) { 1002 1003 t.Run("check url", func(t *testing.T) { 1004 assert.Equal(t, "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo?sap-client=000", httpClient.URL) 1005 }) 1006 1007 t.Run("check method", func(t *testing.T) { 1008 assert.Equal(t, "GET", httpClient.Method) 1009 }) 1010 1011 } 1012 }) 1013 1014 t.Run("no ATC Checks were found", func(t *testing.T) { 1015 1016 httpClient := httpMockGctsT{StatusCode: 200} 1017 1018 config := gctsExecuteABAPQualityChecksOptions{ 1019 Host: "http://testHost.com:50000", 1020 Client: "000", 1021 Repository: "testRepo", 1022 Username: "testUser", 1023 Password: "testPassword", 1024 Commit: "0123456789abcdefghijkl", 1025 AtcVariant: "CUSTOM_REMOTE_REF", 1026 Scope: "repository", 1027 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 1028 AtcResultsFileName: "ATCResults.xml", 1029 } 1030 1031 object := repoObject{ 1032 Pgmid: "R3TR", 1033 Object: "ZP_NON_EXISTANT", 1034 Type: "CLAS", 1035 Description: "Clas Object", 1036 } 1037 1038 var repoObjects []repoObject 1039 repoObjects = append(repoObjects, object) 1040 err := executeATCCheck(&config, &httpClient, repoObjects) 1041 1042 if assert.NoError(t, err) { 1043 1044 t.Run("check url", func(t *testing.T) { 1045 assert.Equal(t, "http://testHost.com:50000/sap/bc/adt/atc/worklists/3E3D0764F95Z01ABCDHEF9C9F6B5C14P?sap-client=000", httpClient.URL) 1046 }) 1047 1048 t.Run("check method", func(t *testing.T) { 1049 assert.Equal(t, "GET", httpClient.Method) 1050 }) 1051 1052 } 1053 }) 1054 } 1055 1056 func TestExecuteATCCheckFailure(t *testing.T) { 1057 1058 object := repoObject{ 1059 Pgmid: "R3TR", 1060 Object: "ZP_PIPER", 1061 Type: "CLAS", 1062 Description: "Clas Object", 1063 } 1064 1065 var repoObjects []repoObject 1066 repoObjects = append(repoObjects, object) 1067 1068 config := gctsExecuteABAPQualityChecksOptions{ 1069 Host: "http://testHost.com:50000", 1070 Client: "000", 1071 Repository: "testRepo", 1072 Username: "testUser", 1073 Password: "testPassword", 1074 Commit: "0123456789abcdefghijkl", 1075 Scope: "repository", 1076 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 1077 AtcResultsFileName: "ATCResults.xml", 1078 } 1079 1080 t.Run("a http error occurred", func(t *testing.T) { 1081 1082 httpClient := httpMockGcts{StatusCode: 403, ResponseBody: ` 1083 CSRF token validation failed 1084 `} 1085 1086 header := make(http.Header) 1087 header.Add("Accept", "application/atomsvc+xml") 1088 header.Add("x-csrf-token", "ZegUEgfa50R7ZfGGxOtx2A==") 1089 header.Add("saml2", "disabled") 1090 1091 err := executeATCCheck(&config, &httpClient, repoObjects) 1092 1093 assert.EqualError(t, err, "execution of ATC Checks failed: get worklist failed: discovery of the ABAP server failed: a http error occurred") 1094 1095 }) 1096 } 1097 1098 func TestParseAUnitResultSuccess(t *testing.T) { 1099 1100 config := gctsExecuteABAPQualityChecksOptions{ 1101 Host: "http://testHost.com:50000", 1102 Client: "000", 1103 Repository: "testRepo", 1104 Username: "testUser", 1105 Password: "testPassword", 1106 Commit: "0123456789abcdefghijkl", 1107 Scope: "repository", 1108 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 1109 AUnitResultsFileName: "AUnitResults.xml", 1110 } 1111 1112 t.Run("unit test is successful", func(t *testing.T) { 1113 1114 httpClient := httpMockGctsT{StatusCode: 200} 1115 1116 var xmlBody = []byte(` 1117 <?xml version="1.0" encoding="utf-8"?> 1118 <aunit:runResult xmlns:aunit="http://www.sap.com/adt/aunit"> 1119 <program adtcore:uri="/sap/bc/adt/oo/classes/zcl_gcts" adtcore:type="CLAS/OC" adtcore:name="ZCL_GCTS" uriType="semantic" xmlns:adtcore="http://www.sap.com/adt/core"> 1120 <testClasses> 1121 <testClass adtcore:uri="/sap/bc/adt/oo/classes/zcl_gcts/includes/testclasses#type=CLAS%2FOCL;name=LTCL_MASTER" adtcore:type="CLAS/OL" adtcore:name="LTCL_MASTER" uriType="semantic" navigationUri="/sap/bc/adt/oo/classes/zcl_gcts/includes/testclasses#type=CLAS%2FOCL;name=LTCL_MASTER" durationCategory="short" riskLevel="harmless"> 1122 <testMethods> 1123 <testMethod adtcore:uri="/sap/bc/adt/oo/classes/zcl_gcts/includes/testclasses#type=CLAS%2FOLD;name=LTCL_MASTER%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20CHECK" adtcore:type="CLAS/OLI" adtcore:name="CHECK" executionTime="0" uriType="semantic" navigationUri="/sap/bc/adt/oo/classes/zcl_gcts/includes/testclasses#type=CLAS%2FOLD;name=LTCL_MASTER%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20CHECK" unit="s"/> 1124 </testMethods> 1125 </testClass> 1126 </testClasses> 1127 </program> 1128 </aunit:runResult> 1129 `) 1130 1131 var resp *runResult 1132 xml.Unmarshal(xmlBody, &resp) 1133 1134 parsedRes, err := parseUnitResult(&config, &httpClient, resp) 1135 1136 if assert.NoError(t, err) { 1137 1138 t.Run("check url", func(t *testing.T) { 1139 assert.Equal(t, "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo?sap-client=000", httpClient.URL) 1140 }) 1141 1142 t.Run("check method", func(t *testing.T) { 1143 assert.Equal(t, "GET", httpClient.Method) 1144 }) 1145 1146 t.Run("check file name", func(t *testing.T) { 1147 assert.Equal(t, "/var/jenkins_home/workspace/myFirstPipeline//objects/CLAS/ZCL_GCTS/CINC ZCL_GCTS======================CCAU.abap", parsedRes.File[0].Name) 1148 }) 1149 1150 } 1151 }) 1152 1153 t.Run("unit test failed", func(t *testing.T) { 1154 1155 httpClient := httpMockGctsT{StatusCode: 200} 1156 1157 var xmlBody = []byte(`<?xml version="1.0" encoding="utf-8"?> 1158 <aunit:runResult xmlns:aunit="http://www.sap.com/adt/aunit"> 1159 <program adtcore:uri="/sap/bc/adt/oo/classes/zcl_gcts_piper_demo" adtcore:type="CLAS/OC" adtcore:name="ZCL_GCTS_PIPER_DEMO" uriType="semantic" xmlns:adtcore="http://www.sap.com/adt/core"> 1160 <testClasses> 1161 <testClass adtcore:uri="/sap/bc/adt/oo/classes/zcl_gcts_piper_demo/includes/testclasses#type=CLAS%2FOCL;name=LTCL_MASTER" adtcore:type="CLAS/OL" adtcore:name="LTCL_MASTER" uriType="semantic" navigationUri="/sap/bc/adt/oo/classes/zcl_gcts_piper_demo/includes/testclasses#type=CLAS%2FOCL;name=LTCL_MASTER" durationCategory="short" riskLevel="harmless"> 1162 <testMethods> 1163 <testMethod adtcore:uri="/sap/bc/adt/oo/classes/zcl_gcts_piper_demo/includes/testclasses#type=CLAS%2FOLD;name=LTCL_MASTER%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20CHECK" adtcore:type="CLAS/OLI" adtcore:name="CHECK" executionTime="0" uriType="semantic" navigationUri="/sap/bc/adt/oo/classes/zcl_gcts_piper_demo/includes/testclasses#type=CLAS%2FOLD;name=LTCL_MASTER%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20CHECK" unit="s"> 1164 <alerts> 1165 <alert kind="failedAssertion" severity="critical"> 1166 <title>Critical Assertion Error: 'Check: ASSERT_EQUALS'</title> 1167 <details> 1168 <detail text="Different Values:"> 1169 <details> 1170 <detail text="Expected [Hello] Actual [Hello2]"/> 1171 </details> 1172 </detail> 1173 <detail text="Test 'LTCL_MASTER->CHECK' in Main Program 'ZCL_GCTS_PIPER_DEMO===========CP'."/> 1174 </details> 1175 <stack> 1176 <stackEntry adtcore:uri="/sap/bc/adt/oo/classes/zcl_gcts_piper_demo/includes/testclasses#start=21,0" adtcore:type="CLAS/OCN/testclasses" adtcore:name="ZCL_GCTS_PIPER_DEMO" adtcore:description="Include: <ZCL_GCTS_PIPER_DEMO===========CCAU> Line: <21> (CHECK)"/> 1177 </stack> 1178 </alert> 1179 </alerts> 1180 </testMethod> 1181 </testMethods> 1182 </testClass> 1183 </testClasses> 1184 </program> 1185 </aunit:runResult>`) 1186 1187 var resp *runResult 1188 xml.Unmarshal(xmlBody, &resp) 1189 1190 parsedRes, err := parseUnitResult(&config, &httpClient, resp) 1191 1192 if assert.NoError(t, err) { 1193 1194 t.Run("check url", func(t *testing.T) { 1195 assert.Equal(t, "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo?sap-client=000", httpClient.URL) 1196 }) 1197 1198 t.Run("check method", func(t *testing.T) { 1199 assert.Equal(t, "GET", httpClient.Method) 1200 }) 1201 1202 t.Run("check file name", func(t *testing.T) { 1203 assert.Equal(t, "/var/jenkins_home/workspace/myFirstPipeline//objects/CLAS/ZCL_GCTS_PIPER_DEMO/CINC ZCL_GCTS_PIPER_DEMO===========CCAU.abap", parsedRes.File[0].Name) 1204 }) 1205 1206 t.Run("check line number", func(t *testing.T) { 1207 assert.Equal(t, "21", parsedRes.File[0].Error[0].Line) 1208 }) 1209 1210 t.Run("check severity", func(t *testing.T) { 1211 assert.Equal(t, "error", parsedRes.File[0].Error[0].Severity) 1212 }) 1213 1214 t.Run("check source", func(t *testing.T) { 1215 assert.Equal(t, "LTCL_MASTER/CHECK", parsedRes.File[0].Error[0].Source) 1216 }) 1217 1218 t.Run("check message", func(t *testing.T) { 1219 assert.Equal(t, " Different Values: Expected [Hello] Actual [Hello2] Test 'LTCL_MASTER->CHECK' in Main Program 'ZCL_GCTS_PIPER_DEMO===========CP'.", parsedRes.File[0].Error[0].Message) 1220 }) 1221 1222 } 1223 }) 1224 1225 } 1226 1227 func TestParseAUnitResultFailure(t *testing.T) { 1228 1229 config := gctsExecuteABAPQualityChecksOptions{ 1230 Host: "http://testHost.com:50000", 1231 Client: "000", 1232 Repository: "testRepo", 1233 Username: "testUser", 1234 Password: "testPassword", 1235 Commit: "0123456789abcdefghijkl", 1236 AtcVariant: "DEFAULT_REMOTE_REF", 1237 Scope: "repository", 1238 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 1239 AUnitResultsFileName: "AUnitResults.xml", 1240 } 1241 1242 t.Run("parser fails", func(t *testing.T) { 1243 1244 httpClient := httpMockGctsT{StatusCode: 403} 1245 1246 var xmlBody = []byte(`<?xml version="1.0" encoding="utf-8"?> 1247 <aunit:runResult xmlns:aunit="http://www.sap.com/adt/aunit"> 1248 <program adtcore:uri="/sap/bc/adt/oo/classes/zcl_gcts_piper_demo" adtcore:type="CLAS/OC" adtcore:name="ZCL_GCTS_PIPER_DEMO" uriType="semantic" xmlns:adtcore="http://www.sap.com/adt/core"> 1249 <testClasses> 1250 <testClass adtcore:uri="/sap/bc/adt/oo/classes/zcl_gcts_piper_demo/includes/testclasses#type=CLAS%2FOCL;name=LTCL_MASTER" adtcore:type="CLAS/OL" adtcore:name="LTCL_MASTER" uriType="semantic" navigationUri="/sap/bc/adt/oo/classes/zcl_gcts_piper_demo/includes/testclasses#type=CLAS%2FOCL;name=LTCL_MASTER" durationCategory="short" riskLevel="harmless"> 1251 <testMethods> 1252 <testMethod adtcore:uri="/sap/bc/adt/oo/classes/zcl_gcts_piper_demo/includes/testclasses#type=CLAS%2FOLD;name=LTCL_MASTER%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20CHECK" adtcore:type="CLAS/OLI" adtcore:name="CHECK" executionTime="0" uriType="semantic" navigationUri="/sap/bc/adt/oo/classes/zcl_gcts_piper_demo/includes/testclasses#type=CLAS%2FOLD;name=LTCL_MASTER%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20CHECK" unit="s"> 1253 <alerts> 1254 <alert kind="failedAssertion" severity="critical"> 1255 <title>Critical Assertion Error: 'Check: ASSERT_EQUALS'</title> 1256 <details> 1257 <detail text="Different Values:"> 1258 <details> 1259 <detail text="Expected [Hello] Actual [Hello2]"/> 1260 </details> 1261 </detail> 1262 <detail text="Test 'LTCL_MASTER->CHECK' in Main Program 'ZCL_GCTS_PIPER_DEMO===========CP'."/> 1263 </details> 1264 <stack> 1265 <stackEntry adtcore:uri="/sap/bc/adt/oo/classes/zcl_gcts_piper_demo/includes/testclasses#start=21,0" adtcore:type="CLAS/OCN/testclasses" adtcore:name="ZCL_GCTS_PIPER_DEMO" adtcore:description="Include: <ZCL_GCTS_PIPER_DEMO===========CCAU> Line: <21> (CHECK)"/> 1266 </stack> 1267 </alert> 1268 </alerts> 1269 </testMethod> 1270 </testMethods> 1271 </testClass> 1272 </testClasses> 1273 </program> 1274 </aunit:runResult>`) 1275 1276 var resp *runResult 1277 xml.Unmarshal(xmlBody, &resp) 1278 1279 parsedRes, err := parseUnitResult(&config, &httpClient, resp) 1280 1281 if assert.Error(t, err) { 1282 1283 t.Run("check method", func(t *testing.T) { 1284 assert.Equal(t, "parse AUnit Result failed: get file name has failed: could not check readable source format: could not get repository layout: a http error occurred", err.Error()) 1285 }) 1286 1287 assert.NotEmpty(t, parsedRes, "results are not empty") 1288 1289 } 1290 }) 1291 1292 } 1293 1294 func TestParseATCCheckResultSuccess(t *testing.T) { 1295 1296 config := gctsExecuteABAPQualityChecksOptions{ 1297 Host: "http://testHost.com:50000", 1298 Client: "000", 1299 Repository: "testRepo", 1300 Username: "testUser", 1301 Password: "testPassword", 1302 Commit: "0123456789abcdefghijkl", 1303 AtcVariant: "DEFAULT_REMOTE_REF", 1304 Scope: "repository", 1305 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 1306 AtcResultsFileName: "ATCResults.xml", 1307 } 1308 1309 t.Run("atc found", func(t *testing.T) { 1310 1311 httpClient := httpMockGctsT{StatusCode: 200} 1312 1313 var xmlBody = []byte(`<?xml version="1.0" encoding="utf-8"?> 1314 <atcworklist:worklist atcworklist:id="248A076493C01EEC8FA9CEAED527BD53" atcworklist:timestamp="2021-11-04T09:08:18Z" atcworklist:usedObjectSet="99999999999999999999999999999999" atcworklist:objectSetIsComplete="true" xmlns:atcworklist="http://www.sap.com/adt/atc/worklist"> 1315 <atcworklist:objectSets> 1316 <atcworklist:objectSet atcworklist:name="00000000000000000000000000000000" atcworklist:title="All Objects" atcworklist:kind="ALL"/> 1317 <atcworklist:objectSet atcworklist:name="99999999999999999999999999999999" atcworklist:title="Last Check Run" atcworklist:kind="LAST_RUN"/> 1318 </atcworklist:objectSets> 1319 <atcworklist:objects> 1320 <atcobject:object adtcore:uri="/sap/bc/adt/atc/objects/R3TR/CLAS/ZCL_GCTS" adtcore:type="CLAS" adtcore:name="ZCL_GCTS" adtcore:packageName="ZPL_GCTS" atcobject:author="testUser" xmlns:atcobject="http://www.sap.com/adt/atc/object" xmlns:adtcore="http://www.sap.com/adt/core"> 1321 <atcobject:findings> 1322 <atcfinding:finding adtcore:uri="/sap/bc/adt/atc/findings/itemid/248A076493C01EEC8FA9D609860AFD93/index/233439" atcfinding:location="/sap/bc/adt/oo/classes/zcl_gcts/source/main#type=CLAS%2FOSI;name=ZCL_GCTS;start=20" atcfinding:processor="testUser" atcfinding:lastChangedBy="testUser" atcfinding:priority="1" atcfinding:checkId="78A08159CD2A822100535FBEB655BDB8" atcfinding:checkTitle="Package Check (Remote-enabled)" atcfinding:messageId="USEM" atcfinding:messageTitle="Package Violation - Error" atcfinding:exemptionApproval="" atcfinding:exemptionKind="" atcfinding:checksum="553596936" atcfinding:quickfixInfo="atc:248A076493C01EEC8FA9D609860AFD93,233439" xmlns:atcfinding="http://www.sap.com/adt/atc/finding"> 1323 <atom:link href="/sap/bc/adt/documentation/atc/documents/itemid/248A076493C01EEC8FA9D609860AFD93/index/233439" rel="http://www.sap.com/adt/relations/documentation" type="text/html" xmlns:atom="http://www.w3.org/2005/Atom"/> 1324 <atcfinding:quickfixes atcfinding:manual="false" atcfinding:automatic="false" atcfinding:pseudo="false"/> 1325 </atcfinding:finding> 1326 </atcobject:findings> 1327 </atcobject:object> 1328 </atcworklist:objects> 1329 </atcworklist:worklist>`) 1330 1331 var resp *worklist 1332 1333 xml.Unmarshal(xmlBody, &resp) 1334 1335 parsedRes, err := parseATCCheckResult(&config, &httpClient, resp) 1336 1337 if assert.NoError(t, err) { 1338 1339 t.Run("check file name", func(t *testing.T) { 1340 assert.Equal(t, "/var/jenkins_home/workspace/myFirstPipeline//objects/CLAS/ZCL_GCTS/CPRI ZCL_GCTS.abap", parsedRes.File[0].Name) 1341 }) 1342 1343 t.Run("check line number", func(t *testing.T) { 1344 assert.Equal(t, "20", parsedRes.File[0].Error[0].Line) 1345 }) 1346 1347 t.Run("check severity", func(t *testing.T) { 1348 assert.Equal(t, "error", parsedRes.File[0].Error[0].Severity) 1349 }) 1350 1351 t.Run("check source", func(t *testing.T) { 1352 assert.Equal(t, "ZCL_GCTS", parsedRes.File[0].Error[0].Source) 1353 }) 1354 1355 t.Run("check message", func(t *testing.T) { 1356 assert.Equal(t, "Package Check (Remote-enabled) Package Violation - Error", parsedRes.File[0].Error[0].Message) 1357 }) 1358 1359 assert.NotEmpty(t, parsedRes, "results are not empty") 1360 1361 } 1362 }) 1363 1364 t.Run("no ATC Checks were found", func(t *testing.T) { 1365 1366 config := gctsExecuteABAPQualityChecksOptions{ 1367 Host: "http://testHost.com:50000", 1368 Client: "000", 1369 Repository: "testRepo", 1370 Username: "testUser", 1371 Password: "testPassword", 1372 Commit: "0123456789abcdefghijkl", 1373 AtcVariant: "DEFAULT_REMOTE_REF", 1374 Scope: "repository", 1375 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 1376 AtcResultsFileName: "ATCResults.xml", 1377 } 1378 1379 httpClient := httpMockGctsT{StatusCode: 200} 1380 1381 var xmlBody = []byte(`<?xml version="1.0" encoding="utf-8"?> 1382 <atcworklist:worklist atcworklist:id="248A076493C01EEC8FA9CEAED527BD53" atcworklist:timestamp="2021-11-08T08:44:40Z" atcworklist:usedObjectSet="99999999999999999999999999999999" atcworklist:objectSetIsComplete="true" xmlns:atcworklist="http://www.sap.com/adt/atc/worklist"> 1383 <atcworklist:objectSets> 1384 <atcworklist:objectSet atcworklist:name="00000000000000000000000000000000" atcworklist:title="All Objects" atcworklist:kind="ALL"/> 1385 <atcworklist:objectSet atcworklist:name="99999999999999999999999999999999" atcworklist:title="Last Check Run" atcworklist:kind="LAST_RUN"/> 1386 </atcworklist:objectSets> 1387 <atcworklist:objects/> 1388 </atcworklist:worklist>`) 1389 var resp *worklist 1390 xml.Unmarshal(xmlBody, &resp) 1391 parsedRes, err := parseATCCheckResult(&config, &httpClient, resp) 1392 1393 if assert.NoError(t, err) { 1394 1395 assert.Equal(t, parsedRes.Version, "1.0") 1396 1397 } 1398 }) 1399 1400 } 1401 1402 func TestParseATCCheckResultFailure(t *testing.T) { 1403 1404 config := gctsExecuteABAPQualityChecksOptions{ 1405 Host: "http://testHost.com:50000", 1406 Client: "000", 1407 Repository: "testRepo", 1408 Username: "testUser", 1409 Password: "testPassword", 1410 Commit: "0123456789abcdefghijkl", 1411 AtcVariant: "DEFAULT_REMOTE_REF", 1412 Scope: "repsoitory", 1413 Workspace: "/var/jenkins_home/workspace/myFirstPipeline", 1414 AtcResultsFileName: "ATCResults.xml", 1415 } 1416 1417 t.Run("a http error occurred", func(t *testing.T) { 1418 1419 httpClient := httpMockGctsT{StatusCode: 403} 1420 1421 var xmlBody = []byte(`<?xml version="1.0" encoding="utf-8"?> 1422 <atcworklist:worklist atcworklist:id="248A076493C01EEC8FA9CEAED527BD53" atcworklist:timestamp="2021-11-04T09:08:18Z" atcworklist:usedObjectSet="99999999999999999999999999999999" atcworklist:objectSetIsComplete="true" xmlns:atcworklist="http://www.sap.com/adt/atc/worklist"> 1423 <atcworklist:objectSets> 1424 <atcworklist:objectSet atcworklist:name="00000000000000000000000000000000" atcworklist:title="All Objects" atcworklist:kind="ALL"/> 1425 <atcworklist:objectSet atcworklist:name="99999999999999999999999999999999" atcworklist:title="Last Check Run" atcworklist:kind="LAST_RUN"/> 1426 </atcworklist:objectSets> 1427 <atcworklist:objects> 1428 <atcobject:object adtcore:uri="/sap/bc/adt/atc/objects/R3TR/CLAS/ZCL_GCTS" adtcore:type="CLAS" adtcore:name="ZCL_GCTS" adtcore:packageName="ZPL_GCTS" atcobject:author="testUser" xmlns:atcobject="http://www.sap.com/adt/atc/object" xmlns:adtcore="http://www.sap.com/adt/core"> 1429 <atcobject:findings> 1430 <atcfinding:finding adtcore:uri="/sap/bc/adt/atc/findings/itemid/248A076493C01EEC8FA9D609860AFD93/index/233439" atcfinding:location="/sap/bc/adt/oo/classes/zcl_gcts/source/main#type=CLAS%2FOSI;name=ZCL_GCTS;start=20" atcfinding:processor="testUser" atcfinding:lastChangedBy="testUser" atcfinding:priority="1" atcfinding:checkId="78A08159CD2A822100535FBEB655BDB8" atcfinding:checkTitle="Package Check (Remote-enabled)" atcfinding:messageId="USEM" atcfinding:messageTitle="Package Violation - Error" atcfinding:exemptionApproval="" atcfinding:exemptionKind="" atcfinding:checksum="553596936" atcfinding:quickfixInfo="atc:248A076493C01EEC8FA9D609860AFD93,233439" xmlns:atcfinding="http://www.sap.com/adt/atc/finding"> 1431 <atom:link href="/sap/bc/adt/documentation/atc/documents/itemid/248A076493C01EEC8FA9D609860AFD93/index/233439" rel="http://www.sap.com/adt/relations/documentation" type="text/html" xmlns:atom="http://www.w3.org/2005/Atom"/> 1432 <atcfinding:quickfixes atcfinding:manual="false" atcfinding:automatic="false" atcfinding:pseudo="false"/> 1433 </atcfinding:finding> 1434 </atcobject:findings> 1435 </atcobject:object> 1436 </atcworklist:objects> 1437 </atcworklist:worklist>`) 1438 1439 var resp *worklist 1440 xml.Unmarshal(xmlBody, &resp) 1441 parsedRes, err := parseATCCheckResult(&config, &httpClient, resp) 1442 1443 assert.EqualError(t, err, "conversion of ATC check results to CheckStyle has failed: get file name has failed: could not check readable source format: could not get repository layout: a http error occurred") 1444 assert.NotEmpty(t, parsedRes) 1445 }) 1446 1447 } 1448 1449 type httpMockGctsT struct { 1450 Method string // is set during test execution 1451 URL string // is set before test execution 1452 Header map[string][]string // is set before test execution 1453 ResponseBody string // is set before test execution 1454 Options piperhttp.ClientOptions // is set during test 1455 StatusCode int // is set during test 1456 } 1457 1458 func (c *httpMockGctsT) SetOptions(options piperhttp.ClientOptions) { 1459 c.Options = options 1460 } 1461 1462 func (c *httpMockGctsT) SendRequest(method string, url string, r io.Reader, header http.Header, cookies []*http.Cookie) (*http.Response, error) { 1463 1464 c.Method = method 1465 c.URL = url 1466 1467 switch url { 1468 1469 case "http://testHost.com:50000/sap/bc/adt/core/discovery?sap-client=000": 1470 1471 c.Header = map[string][]string{"X-Csrf-Token": {"ZegUEgfa50R7ZfGGxOtx2A=="}} 1472 1473 c.ResponseBody = ` 1474 <?xml version="1.0" encoding="utf-8"?> 1475 <app:service xmlns:app="http://www.w3.org/2007/app" xmlns:atom="http://www.w3.org/2005/Atom"/> 1476 ` 1477 1478 case "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo?sap-client=000": 1479 1480 c.ResponseBody = ` 1481 { 1482 "result": { 1483 1484 "rid": "testRepo", 1485 "name": "testRepo", 1486 "role": "PROVIDED", 1487 "type": "GIT", 1488 "vsid": "vSID", 1489 "privateFlag": "false", 1490 "url": "http://github.com/testRepo", 1491 "createdBy": "testUser", 1492 "createdDate": "02/02/2022", 1493 "objects": 3, 1494 "currentCommit": "xyz987654321" 1495 } 1496 } 1497 ` 1498 case "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo2?sap-client=000": 1499 1500 c.ResponseBody = ` 1501 { 1502 "result": { 1503 1504 "rid": "testRepo2", 1505 "name": "testRepo2", 1506 "role": "PROVIDED", 1507 "type": "GIT", 1508 "vsid": "vSID", 1509 "privateFlag": "false", 1510 "url": "http://github.com/testRepo2", 1511 "createdBy": "testUser", 1512 "createdDate": "02/02/2022", 1513 "objects": 3, 1514 "currentCommit": "xyz987654321" 1515 } 1516 1517 } 1518 ` 1519 1520 case "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo/getCommit?sap-client=000": 1521 1522 c.ResponseBody = ` 1523 { 1524 "commits": [ 1525 { 1526 1527 "id": "0123456789abcdefghijkl" 1528 1529 }, 1530 { 1531 1532 "id": "7845abaujztrw785" 1533 }, 1534 { 1535 1536 "id": "45poiztr785423" 1537 } 1538 ] 1539 } 1540 ` 1541 1542 case "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo2/getCommit?sap-client=000": 1543 1544 c.ResponseBody = ` 1545 { 1546 "commits": [ 1547 { 1548 1549 "id": "0123456789abcdefghijkl" 1550 1551 }, 1552 { 1553 1554 "id": "7845abaujztrw785" 1555 }, 1556 { 1557 1558 "id": "45poiztr785423" 1559 } 1560 ] 1561 } 1562 ` 1563 1564 case "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo/getHistory?sap-client=000": 1565 1566 c.ResponseBody = ` 1567 { 1568 "result": [ 1569 { 1570 1571 "rid": "testRepo", 1572 "checkoutTime": 20220216233655, 1573 "fromCommit": "xyz987654321", 1574 "toCommit": "0123456789abcdefghijkl", 1575 "caller": "USER", 1576 "type": "PULL" 1577 }, 1578 { 1579 "rid": "testRepo", 1580 "checkoutTime": 20220216233788, 1581 "fromCommit": "ghi98765432", 1582 "toCommit": "xyz987654321", 1583 "caller": "USER", 1584 "type": "PULL" 1585 } 1586 ] 1587 } 1588 ` 1589 1590 case "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo2/getHistory?sap-client=000": 1591 1592 c.ResponseBody = ` 1593 { 1594 "result": [ 1595 { 1596 1597 "rid": "testRepo", 1598 "checkoutTime": 20220216233655, 1599 "fromCommit": "xyz987654321", 1600 "toCommit": "0123456789abcdefghijkl", 1601 "caller": "USER", 1602 "type": "PULL" 1603 }, 1604 { 1605 "rid": "testRepo", 1606 "checkoutTime": 20220216233788, 1607 "fromCommit": "ghi98765432", 1608 "toCommit": "xyz987654321", 1609 "caller": "USER", 1610 "type": "PULL" 1611 } 1612 ] 1613 } 1614 ` 1615 1616 case "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo/compareCommits?fromCommit=xyz987654321&toCommit=0123456789abcdefghijkl&sap-client=000": 1617 1618 c.ResponseBody = ` 1619 { 1620 "objects": [ 1621 { 1622 1623 "name": "ZCL_GCTS", 1624 "type": "CLAS", 1625 "action": "Class (ABAP Objects)" 1626 }, 1627 { 1628 1629 "name": "ZP_GCTS", 1630 "type": "DEVC", 1631 "action": "Package(ABAP Objects)" 1632 }, 1633 { 1634 1635 "name": "ZIF_GCTS_API", 1636 "type": "INTF", 1637 "action": "Interface (ABAP Objects)" 1638 } 1639 ] 1640 } 1641 ` 1642 1643 case "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo/compareCommits?fromCommit=7845abaujztrw785&toCommit=0123456789abcdefghijkl&sap-client=000": 1644 1645 c.ResponseBody = ` 1646 { 1647 "objects": [ 1648 { 1649 1650 "name": "ZCL_GCTS", 1651 "type": "CLAS", 1652 "action": "Class (ABAP Objects)" 1653 }, 1654 { 1655 1656 "name": "ZP_GCTS", 1657 "type": "DEVC", 1658 "action": "Package(ABAP Objects)" 1659 }, 1660 { 1661 1662 "name": "ZIF_GCTS_API", 1663 "type": "INTF", 1664 "action": "Interface (ABAP Objects)" 1665 } 1666 ] 1667 } 1668 ` 1669 case "http://testHost.com:50000/sap/bc/cts_abapvcs/objects/CLAS/ZCL_GCTS?sap-client=000": 1670 1671 c.ResponseBody = ` 1672 1673 { 1674 1675 "pgmid": "R3TR", 1676 "object": "CLAS", 1677 "objName": "ZCL_GCTS", 1678 "srcsystem": "src", 1679 "author": "HUGO", 1680 "devclass": "SGCTS" 1681 } 1682 ` 1683 1684 case "http://testHost.com:50000/sap/bc/cts_abapvcs/objects/INTF/ZIF_GCTS_API?sap-client=000": 1685 1686 c.ResponseBody = ` 1687 1688 { 1689 1690 "pgmid": "R3TR", 1691 "object": "INTF", 1692 "objName": "ZIF_GCTS_API", 1693 "srcsystem": "src", 1694 "author": "HUGO", 1695 "devclass": "SGCTS_2" 1696 } 1697 ` 1698 1699 case "http://testHost.com:50000/sap/bc/cts_abapvcs/objects/DEVC/ZP_GCTS?sap-client=000": 1700 1701 c.ResponseBody = ` 1702 1703 { 1704 1705 "pgmid": "R3TR", 1706 "object": "DEVC", 1707 "objName": "ZP_GCTS", 1708 "srcsystem": "src", 1709 "author": "HUGO", 1710 "devclass": "SGCTS" 1711 } 1712 ` 1713 1714 case "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo/layout?sap-client=000": 1715 1716 c.ResponseBody = 1717 `{ 1718 "layout": { 1719 "formatVersion": 5, 1720 "format": "json", 1721 "objectStorage": "plain", 1722 "metaInformation": ".gctsmetadata/", 1723 "tableContent": "true", 1724 "subdirectory": "src/", 1725 "readableSource": "false" 1726 } 1727 } 1728 ` 1729 1730 case "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo/objects?sap-client=000": 1731 1732 c.ResponseBody = ` 1733 { 1734 "objects": [ 1735 { 1736 "pgmid": "R3TR", 1737 "object": "ZCL_GCTS", 1738 "type": "CLAS", 1739 "description": "Class (ABAP Objects)" 1740 }, 1741 { 1742 1743 "pgmid": "R3TR", 1744 "object": "ZP_GCTS", 1745 "type": "DEVC", 1746 "description": "Package(ABAP Objects)" 1747 }, 1748 { 1749 "pgmid": "R3TR", 1750 "object": "ZIF_GCTS_API", 1751 "type": "INTF", 1752 "description": "Interface (ABAP Objects)" 1753 } 1754 ] 1755 } 1756 ` 1757 1758 case "http://testHost.com:50000/sap/bc/adt/abapunit/testruns?sap-client=000": 1759 1760 c.Header = map[string][]string{"Accept": {"application/xml"}} 1761 c.Header = map[string][]string{"x-csrf-token": {"ZegUEgfa50R7ZfGGxOtx2A=="}} 1762 c.Header = map[string][]string{"Content-Type": {"application/vnd.sap.adt.abapunit.testruns.result.v1+xml"}} 1763 1764 c.ResponseBody = ` 1765 <?xml version="1.0" encoding="utf-8"?> 1766 <aunit:runResult xmlns:aunit="http://www.sap.com/adt/aunit"> 1767 <program adtcore:uri="/sap/bc/adt/oo/classes/zcl_gcts_piper_demo" adtcore:type="CLAS/OC" adtcore:name="ZCL_GCTS" uriType="semantic" xmlns:adtcore="http://www.sap.com/adt/core"> 1768 <testClasses> 1769 <testClass adtcore:uri="/sap/bc/adt/oo/classes/zcl_gcts/includes/testclasses#type=CLAS%2FOCL;name=LTCL_MASTER" adtcore:type="CLAS/OL" adtcore:name="LTCL_MASTER" uriType="semantic" navigationUri="/sap/bc/adt/oo/classes/zcl_gcts/includes/testclasses#type=CLAS%2FOCL;name=LTCL_MASTER" durationCategory="short" riskLevel="harmless"> 1770 <testMethods> 1771 <testMethod adtcore:uri="/sap/bc/adt/oo/classes/zcl_gcts/includes/testclasses#type=CLAS%2FOLD;name=LTCL_MASTER%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20CHECK" adtcore:type="CLAS/OLI" adtcore:name="CHECK" executionTime="0" uriType="semantic" navigationUri="/sap/bc/adt/oo/classes/zcl_gcts/includes/testclasses#type=CLAS%2FOLD;name=LTCL_MASTER%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20CHECK" unit="s"/> 1772 </testMethods> 1773 </testClass> 1774 </testClasses> 1775 </program> 1776 </aunit:runResult> 1777 ` 1778 1779 case "http://testHost.com:50000/sap/bc/adt/atc/worklists?checkVariant=DEFAULT_REMOTE_REF&sap-client=000": 1780 1781 c.Header = map[string][]string{"Location": {"/atc/worklists/worklistId/123Z076495C01ABCDEF9C9F6B257OD70"}} 1782 1783 case "http://testHost.com:50000/sap/bc/adt/atc/worklists?checkVariant=CUSTOM_REMOTE_REF&sap-client=000": 1784 1785 c.Header = map[string][]string{"Location": {"/atc/worklists/worklistId/3E3D0764F95Z01ABCDHEF9C9F6B5C14P"}} 1786 1787 case "http://testHost.com:50000/sap/bc/adt/atc/runs?worklistId=123Z076495C01ABCDEF9C9F6B257OD70?sap-client=000": 1788 1789 c.ResponseBody = 1790 `<?xml version="1.0" encoding="utf-8"?> 1791 <atcworklist:worklistRun xmlns:atcworklist="http://www.sap.com/adt/atc/worklist"> 1792 <atcworklist:worklistId>123Z076495C01ABCDEF9C9F6B257OD70</atcworklist:worklistId> 1793 <atcworklist:worklistTimestamp>2021-11-29T14:46:46Z</atcworklist:worklistTimestamp> 1794 <atcworklist:infos> 1795 <atcinfo:info xmlns:atcinfo="http://www.sap.com/adt/atc/info"> 1796 <atcinfo:type>FINDING_STATS</atcinfo:type> 1797 <atcinfo:description>0,0,1</atcinfo:description> 1798 </atcinfo:info> 1799 </atcworklist:infos> 1800 </atcworklist:worklistRun>` 1801 1802 case "http://testHost.com:50000/sap/bc/adt/atc/worklists/3E3D0764F95Z01ABCDHEF9C9F6B5C14P?sap-client=000": 1803 c.ResponseBody = 1804 `<?xml version="1.0" encoding="utf-8"?> 1805 <atcworklist:worklist atcworklist:id="42010AEF3CA51EDC94AC4683B035E12D" atcworklist:timestamp="2021-11-29T22:18:58Z" atcworklist:usedObjectSet="99999999999999999999999999999999" atcworklist:objectSetIsComplete="true" xmlns:atcworklist="http://www.sap.com/adt/atc/worklist"> 1806 <atcworklist:objectSets> 1807 <atcworklist:objectSet atcworklist:name="00000000000000000000000000000000" atcworklist:title="All Objects" atcworklist:kind="ALL"/> 1808 <atcworklist:objectSet atcworklist:name="99999999999999999999999999999999" atcworklist:title="Last Check Run" atcworklist:kind="LAST_RUN"/> 1809 </atcworklist:objectSets> 1810 <atcworklist:objects/> 1811 </atcworklist:worklist>` 1812 1813 case "http://testHost.com:50000/sap/bc/adt/atc/worklists/123Z076495C01ABCDEF9C9F6B257OD70?sap-client=000": 1814 c.ResponseBody = 1815 `<?xml version="1.0" encoding="utf-8"?> 1816 <atcworklist:worklist atcworklist:id="248A076493C01EEC8FA9CEAED527BD53" atcworklist:timestamp="2021-11-04T09:08:18Z" atcworklist:usedObjectSet="99999999999999999999999999999999" atcworklist:objectSetIsComplete="true" xmlns:atcworklist="http://www.sap.com/adt/atc/worklist"> 1817 <atcworklist:objectSets> 1818 <atcworklist:objectSet atcworklist:name="00000000000000000000000000000000" atcworklist:title="All Objects" atcworklist:kind="ALL"/> 1819 <atcworklist:objectSet atcworklist:name="99999999999999999999999999999999" atcworklist:title="Last Check Run" atcworklist:kind="LAST_RUN"/> 1820 </atcworklist:objectSets> 1821 <atcworklist:objects> 1822 <atcobject:object adtcore:uri="/sap/bc/adt/atc/objects/R3TR/CLAS/ZCL_GCTS" adtcore:type="CLAS" adtcore:name="ZCL_GCTS" adtcore:packageName="ZPL_GCTS" atcobject:author="testUser" xmlns:atcobject="http://www.sap.com/adt/atc/object" xmlns:adtcore="http://www.sap.com/adt/core"> 1823 <atcobject:findings> 1824 <atcfinding:finding adtcore:uri="/sap/bc/adt/atc/findings/itemid/248A076493C01EEC8FA9D609860AFD93/index/233439" atcfinding:location="/sap/bc/adt/oo/classes/zcl_gcts/source/main#type=CLAS%2FOSI;name=ZCL_GCTS;start=20" atcfinding:processor="testUser" atcfinding:lastChangedBy="testUser" atcfinding:priority="1" atcfinding:checkId="78A08159CD2A822100535FBEB655BDB8" atcfinding:checkTitle="Package Check (Remote-enabled)" atcfinding:messageId="USEM" atcfinding:messageTitle="Package Violation - Error" atcfinding:exemptionApproval="" atcfinding:exemptionKind="" atcfinding:checksum="553596936" atcfinding:quickfixInfo="atc:248A076493C01EEC8FA9D609860AFD93,233439" xmlns:atcfinding="http://www.sap.com/adt/atc/finding"> 1825 <atom:link href="/sap/bc/adt/documentation/atc/documents/itemid/248A076493C01EEC8FA9D609860AFD93/index/233439" rel="http://www.sap.com/adt/relations/documentation" type="text/html" xmlns:atom="http://www.w3.org/2005/Atom"/> 1826 <atcfinding:quickfixes atcfinding:manual="false" atcfinding:automatic="false" atcfinding:pseudo="false"/> 1827 </atcfinding:finding> 1828 </atcobject:findings> 1829 </atcobject:object> 1830 </atcworklist:objects> 1831 </atcworklist:worklist>` 1832 } 1833 1834 if r != nil { 1835 _, err := ioutil.ReadAll(r) 1836 1837 if err != nil { 1838 return nil, err 1839 } 1840 } 1841 1842 res := http.Response{ 1843 StatusCode: c.StatusCode, 1844 Header: c.Header, 1845 Body: ioutil.NopCloser(bytes.NewReader([]byte(c.ResponseBody))), 1846 } 1847 1848 if c.StatusCode >= 400 { 1849 return &res, errors.New("a http error occurred") 1850 } 1851 1852 return &res, nil 1853 }