1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-16 11:09:33 +02:00
sap-jenkins-library/cmd/githubCreateIssue_test.go
Sven Merk 6520115950
Upload Fortify scan results to GitHub issue (#3300)
* fix(fortifyExecuteScan): Propagate translation errors

Force translation related errors to stop the execution of the step.

* Extend testcase

* Update fortifyExecuteScan.go

* Fix fmt and test

* Fix code

* feat(fortifyExecuteScan): Create GitHub issue

* Fix expectation

* Fix fmt

* Fix fmt add test

* Added tests

* Go fmt

* Add switch

* Rewrite githubCreateIssue

* Fix tests

* Added switch

* Issue only in case of violations

* Fix CPE reference

* Add  debug message to issue creation/update

* Update fortifyExecuteScan.go

* Add credential for GH to groovy wrapper

* Update fortifyExecuteScan.go
2022-01-21 10:52:17 +01:00

84 lines
2.4 KiB
Go

package cmd
import (
"testing"
"github.com/SAP/jenkins-library/pkg/mock"
"github.com/stretchr/testify/assert"
piperGithub "github.com/SAP/jenkins-library/pkg/github"
)
func TestTransformConfig(t *testing.T) {
t.Parallel()
t.Run("Success", func(t *testing.T) {
// init
filesMock := mock.FilesMock{}
config := githubCreateIssueOptions{
Owner: "TEST",
Repository: "test",
Body: "This is my test body",
Title: "This is my title",
Assignees: []string{"userIdOne", "userIdTwo"},
}
options := piperGithub.CreateIssueOptions{}
// test
err := transformConfig(&config, &options, filesMock.FileRead)
// assert
assert.NoError(t, err)
assert.Equal(t, config.Token, options.Token)
assert.Equal(t, config.APIURL, options.APIURL)
assert.Equal(t, config.Owner, options.Owner)
assert.Equal(t, config.Repository, options.Repository)
assert.Equal(t, []byte(config.Body), options.Body)
assert.Equal(t, config.Title, options.Title)
assert.Equal(t, config.Assignees, options.Assignees)
assert.Equal(t, config.UpdateExisting, options.UpdateExisting)
})
t.Run("Success bodyFilePath", func(t *testing.T) {
// init
filesMock := mock.FilesMock{}
filesMock.AddFile("test.md", []byte("Test markdown"))
config := githubCreateIssueOptions{
Owner: "TEST",
Repository: "test",
BodyFilePath: "test.md",
Title: "This is my title",
Assignees: []string{"userIdOne", "userIdTwo"},
}
options := piperGithub.CreateIssueOptions{}
// test
err := transformConfig(&config, &options, filesMock.FileRead)
// assert
assert.NoError(t, err)
assert.Equal(t, config.Token, options.Token)
assert.Equal(t, config.APIURL, options.APIURL)
assert.Equal(t, config.Owner, options.Owner)
assert.Equal(t, config.Repository, options.Repository)
assert.Equal(t, []byte("Test markdown"), options.Body)
assert.Equal(t, config.Title, options.Title)
assert.Equal(t, config.Assignees, options.Assignees)
assert.Equal(t, config.UpdateExisting, options.UpdateExisting)
})
t.Run("Error - missing issue body", func(t *testing.T) {
// init
filesMock := mock.FilesMock{}
config := githubCreateIssueOptions{}
options := piperGithub.CreateIssueOptions{}
// test
err := transformConfig(&config, &options, filesMock.FileRead)
// assert
assert.EqualError(t, err, "either parameter `body` or parameter `bodyFilePath` is required")
})
}