github.com/xgoffin/jenkins-library@v1.154.0/cmd/transportRequestDocIDFromGit_test.go (about) 1 package cmd 2 3 import ( 4 "errors" 5 "github.com/stretchr/testify/assert" 6 "testing" 7 ) 8 9 func TestTrGitGetChangeDocumentID(t *testing.T) { 10 t.Parallel() 11 12 t.Run("good", func(t *testing.T) { 13 t.Parallel() 14 15 t.Run("getChangeDocumentID", func(t *testing.T) { 16 configMock := newCdIDConfigMock() 17 18 id, err := getChangeDocumentID(configMock.config, &transportRequestUtilsMock{cdID: "56781234"}) 19 20 if assert.NoError(t, err) { 21 assert.Equal(t, id, "56781234") 22 } 23 }) 24 t.Run("runTransportRequestDocIDFromGit", func(t *testing.T) { 25 configMock := newCdIDConfigMock() 26 cpe := &transportRequestDocIDFromGitCommonPipelineEnvironment{} 27 28 err := runTransportRequestDocIDFromGit(configMock.config, nil, &transportRequestUtilsMock{cdID: "56781234"}, cpe) 29 30 if assert.NoError(t, err) { 31 assert.Equal(t, cpe.custom.changeDocumentID, "56781234") 32 } 33 }) 34 35 }) 36 t.Run("bad", func(t *testing.T) { 37 t.Parallel() 38 39 t.Run("runTransportRequestDocIDFromGit", func(t *testing.T) { 40 configMock := newCdIDConfigMock() 41 cpe := &transportRequestDocIDFromGitCommonPipelineEnvironment{} 42 43 err := runTransportRequestDocIDFromGit(configMock.config, nil, &transportRequestUtilsMock{err: errors.New("fail")}, cpe) 44 45 assert.EqualError(t, err, "fail") 46 }) 47 48 }) 49 } 50 51 type cdIDConfigMock struct { 52 config *transportRequestDocIDFromGitOptions 53 } 54 55 func newCdIDConfigMock() *cdIDConfigMock { 56 return &cdIDConfigMock{ 57 config: &transportRequestDocIDFromGitOptions{ 58 GitFrom: "origin/master", 59 GitTo: "HEAD", 60 ChangeDocumentLabel: "ChangeDocument", 61 }, 62 } 63 }