From 3139255312ab3ce46186caa3b2c926df5060293f Mon Sep 17 00:00:00 2001 From: Sven Merk <33895725+nevskrem@users.noreply.github.com> Date: Thu, 6 Feb 2020 09:43:19 +0100 Subject: [PATCH] Fix chars in checkmarx test, improve development.md (#1154) * Fix chars in test * Update DEVELOPMENT.md * Update DEVELOPMENT.md * Update DEVELOPMENT.md --- DEVELOPMENT.md | 29 +++++++++++++++++++++++++++++ cmd/checkmarxExecuteScan_test.go | 32 ++++++++++++++++---------------- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 7f7424d0a..344452d66 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -7,6 +7,7 @@ 1. [Generating step framework](#generating-step-framework) 1. [Logging](#logging) 1. [Error handling](#error-handling) +1. [Debugging](#debugging) ## Getting started @@ -168,3 +169,31 @@ We use [github.com/pkg/errors](https://github.com/pkg/errors) for that. Unit tests are done using basic `golang` means. Additionally we encourage you to use [github.com/stretchr/testify/assert](https://github.com/stretchr/testify/assert) in order to have slimmer assertions if you like. + +## Debugging + +Debugging can be initiated with VS code fairly easily. Compile the binary with spcific compiler flags to turn off optimizations `go build -gcflags "all=-N -l" -o piper.exe`. + +Modify the `launch.json` located in folder `.vscode` of your project root to point with `program` exatly to the binary that you just built with above command - must be an absolute path. In addition add any arguments required for the execution of the Piper step to `args`. What is separated with a blank on the command line must go into a separate string. + +```javascript +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Launch", + "type": "go", + "request": "launch", + "mode": "exec", + "program": "C:/CF@HCP/git/jenkins-library-public/piper.exe", + "env": {}, + "args": ["checkmarxExecuteScan", "--password", "abcd", "--username", "1234", "--projectName", "testProject4711", "--serverUrl", "https://cx.wdf.sap.corp/"] + } + ] +} +``` + +Finally set your breakpoints and use the `Launch` button in the VS code UI to start debugging. diff --git a/cmd/checkmarxExecuteScan_test.go b/cmd/checkmarxExecuteScan_test.go index a3c80191a..0824a19fc 100644 --- a/cmd/checkmarxExecuteScan_test.go +++ b/cmd/checkmarxExecuteScan_test.go @@ -229,9 +229,9 @@ func TestZipFolder(t *testing.T) { t.Run("zip files", func(t *testing.T) { dir, err := ioutil.TempDir("", "test zip files") if err != nil { - t.Fatal("Failed to create temporary directory") + t.Fatal("Failed to create temporary directory") } - // clean up tmp dir + // clean up tmp dir defer os.RemoveAll(dir) ioutil.WriteFile(filepath.Join(dir, "abcd.go"), []byte{byte(1), byte(2), byte(3)}, 0700) @@ -275,9 +275,9 @@ func TestGetDetailedResults(t *testing.T) { `)} dir, err := ioutil.TempDir("", "test detailed results") if err != nil { - t.Fatal("Failed to create temporary directory") + t.Fatal("Failed to create temporary directory") } - // clean up tmp dir + // clean up tmp dir defer os.RemoveAll(dir) result := getDetailedResults(sys, filepath.Join(dir, "abc.xml"), 2635) assert.Equal(t, "2", result["ProjectId"], "Project ID incorrect") @@ -294,9 +294,9 @@ func TestRunScan(t *testing.T) { options := checkmarxExecuteScanOptions{ProjectName: "TestExisting", VulnerabilityThresholdUnit: "absolute", FullScanCycle: "2", Incremental: true, FullScansScheduled: true, Preset: "10048", TeamID: "16", VulnerabilityThresholdEnabled: true, GeneratePdfReport: true} workspace, err := ioutil.TempDir("", "workspace1") if err != nil { - t.Fatal("Failed to create temporary workspace directory") + t.Fatal("Failed to create temporary workspace directory") } - // clean up tmp dir + // clean up tmp dir defer os.RemoveAll(workspace) influx := checkmarxExecuteScanInflux{} @@ -312,9 +312,9 @@ func TestRunScanWOtherCycle(t *testing.T) { options := checkmarxExecuteScanOptions{VulnerabilityThresholdUnit: "percentage", FullScanCycle: "3", Incremental: true, FullScansScheduled: true, Preset: "SAP_JS_Default", TeamID: "16", VulnerabilityThresholdEnabled: true, GeneratePdfReport: true} workspace, err := ioutil.TempDir("", "workspace2") if err != nil { - t.Fatal("Failed to create temporary workspace directory") + t.Fatal("Failed to create temporary workspace directory") } - // clean up tmp dir + // clean up tmp dir defer os.RemoveAll(workspace) influx := checkmarxExecuteScanInflux{} @@ -330,9 +330,9 @@ func TestRunScanForPullRequest(t *testing.T) { options := checkmarxExecuteScanOptions{PullRequestName: "Test_PR-19", ProjectName: "Test_PR-19", VulnerabilityThresholdUnit: "percentage", FullScanCycle: "3", Incremental: true, FullScansScheduled: true, Preset: "SAP_JS_Default", TeamID: "16", VulnerabilityThresholdEnabled: true, GeneratePdfReport: true, AvoidDuplicateProjectScans: false} workspace, err := ioutil.TempDir("", "workspace3") if err != nil { - t.Fatal("Failed to create temporary workspace directory") + t.Fatal("Failed to create temporary workspace directory") } - // clean up tmp dir + // clean up tmp dir defer os.RemoveAll(workspace) influx := checkmarxExecuteScanInflux{} @@ -348,9 +348,9 @@ func TestRunScanForPullRequestProjectNew(t *testing.T) { options := checkmarxExecuteScanOptions{PullRequestName: "PR-17", ProjectName: "Test_PR-19", VulnerabilityThresholdUnit: "percentage", FullScanCycle: "3", Incremental: true, FullScansScheduled: true, Preset: "10048", TeamName: "OpenSource/Cracks/15", VulnerabilityThresholdEnabled: true, GeneratePdfReport: true} workspace, err := ioutil.TempDir("", "workspace4") if err != nil { - t.Fatal("Failed to create temporary workspace directory") + t.Fatal("Failed to create temporary workspace directory") } - // clean up tmp dir + // clean up tmp dir defer os.RemoveAll(workspace) influx := checkmarxExecuteScanInflux{} @@ -386,9 +386,9 @@ func TestRunScanHighViolationPercentage(t *testing.T) { options := checkmarxExecuteScanOptions{VulnerabilityThresholdUnit: "percentage", VulnerabilityThresholdResult: "FAILURE", VulnerabilityThresholdHigh: 100, FullScanCycle: "10", FullScansScheduled: true, Preset: "10048", TeamID: "16", VulnerabilityThresholdEnabled: true, GeneratePdfReport: true} workspace, err := ioutil.TempDir("", "workspace5") if err != nil { - t.Fatal("Failed to create temporary workspace directory") + t.Fatal("Failed to create temporary workspace directory") } - // clean up tmp dir + // clean up tmp dir defer os.RemoveAll(workspace) influx := checkmarxExecuteScanInflux{} @@ -430,9 +430,9 @@ func TestRunScanHighViolationAbsolute(t *testing.T) { options := checkmarxExecuteScanOptions{VulnerabilityThresholdUnit: "absolute", VulnerabilityThresholdResult: "FAILURE", VulnerabilityThresholdLow: 1, FullScanCycle: "10", FullScansScheduled: true, Preset: "10048", TeamID: "16", VulnerabilityThresholdEnabled: true, GeneratePdfReport: true} workspace, err := ioutil.TempDir("", "workspace6") if err != nil { - t.Fatal("Failed to create temporary workspace directory") + t.Fatal("Failed to create temporary workspace directory") } - // clean up tmp dir + // clean up tmp dir defer os.RemoveAll(workspace) influx := checkmarxExecuteScanInflux{}