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