1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/cmd/transportRequestDocIDFromGit_test.go
Jk1484 ffc931aad1
feat(golangBuild): use 'unit' build tag to include tests during test execution (#4345)
* Added unit tag as argument. Added description to runTests command. Changed code generator to have unit build tag in generated unit test files.

* Added unit build tag to all unit test files.

* added to new unit test unit build tag

* Update verify-go.yml

* small fix

---------

Co-authored-by: Muhammadali Nazarov <Muhammadali.Nazarov@acronis.com>
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2023-05-03 21:02:11 +05:00

67 lines
1.6 KiB
Go

//go:build unit
// +build unit
package cmd
import (
"errors"
"github.com/stretchr/testify/assert"
"testing"
)
func TestTrGitGetChangeDocumentID(t *testing.T) {
t.Parallel()
t.Run("good", func(t *testing.T) {
t.Parallel()
t.Run("getChangeDocumentID", func(t *testing.T) {
configMock := newCdIDConfigMock()
id, err := getChangeDocumentID(configMock.config, &transportRequestUtilsMock{cdID: "56781234"})
if assert.NoError(t, err) {
assert.Equal(t, id, "56781234")
}
})
t.Run("runTransportRequestDocIDFromGit", func(t *testing.T) {
configMock := newCdIDConfigMock()
cpe := &transportRequestDocIDFromGitCommonPipelineEnvironment{}
err := runTransportRequestDocIDFromGit(configMock.config, nil, &transportRequestUtilsMock{cdID: "56781234"}, cpe)
if assert.NoError(t, err) {
assert.Equal(t, cpe.custom.changeDocumentID, "56781234")
}
})
})
t.Run("bad", func(t *testing.T) {
t.Parallel()
t.Run("runTransportRequestDocIDFromGit", func(t *testing.T) {
configMock := newCdIDConfigMock()
cpe := &transportRequestDocIDFromGitCommonPipelineEnvironment{}
err := runTransportRequestDocIDFromGit(configMock.config, nil, &transportRequestUtilsMock{err: errors.New("fail")}, cpe)
assert.EqualError(t, err, "fail")
})
})
}
type cdIDConfigMock struct {
config *transportRequestDocIDFromGitOptions
}
func newCdIDConfigMock() *cdIDConfigMock {
return &cdIDConfigMock{
config: &transportRequestDocIDFromGitOptions{
GitFrom: "origin/master",
GitTo: "HEAD",
ChangeDocumentLabel: "ChangeDocument",
},
}
}