1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

chore(jenkins): expose artifacts save method (#2426)

* fix code smell

* expose artifact.Save function

* regenerate mock file
This commit is contained in:
Christopher Fenner 2020-11-26 10:06:14 +01:00 committed by GitHub
parent 26af83b1fc
commit 860b28884c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 4 deletions

View File

@ -5,7 +5,9 @@ import (
)
// Artifact is an interface to abstract gojenkins.Artifact.
// mock generated with: mockery --name Artifact --dir pkg/jenkins --output pkg/jenkins/mocks
type Artifact interface {
Save(path string) (bool, error)
SaveToDir(dir string) (bool, error)
GetData() ([]byte, error)
FileName() string
@ -16,6 +18,11 @@ type ArtifactImpl struct {
artifact gojenkins.Artifact
}
// Save refers to the gojenkins.Artifact.Save function.
func (a *ArtifactImpl) Save(path string) (bool, error) {
return a.artifact.Save(path)
}
// SaveToDir refers to the gojenkins.Artifact.SaveToDir function.
func (a *ArtifactImpl) SaveToDir(dir string) (bool, error) {
return a.artifact.SaveToDir(dir)

View File

@ -34,8 +34,8 @@ func TestFetchBuildArtifact(t *testing.T) {
build.On("IsRunning").Return(false)
build.On("GetArtifacts").Return(
[]gojenkins.Artifact{
gojenkins.Artifact{FileName: mock.Anything},
gojenkins.Artifact{FileName: fileName},
{FileName: mock.Anything},
{FileName: fileName},
},
)
// test
@ -70,7 +70,7 @@ func TestFetchBuildArtifact(t *testing.T) {
// init
build := &mocks.Build{}
build.On("IsRunning").Return(false)
build.On("GetArtifacts").Return([]gojenkins.Artifact{gojenkins.Artifact{FileName: mock.Anything}})
build.On("GetArtifacts").Return([]gojenkins.Artifact{{FileName: mock.Anything}})
// test
_, err := FetchBuildArtifact(build, fileName)
// asserts

View File

@ -1,4 +1,4 @@
// Code generated by mockery v1.0.0. DO NOT EDIT.
// Code generated by mockery v2.0.0-alpha.13. DO NOT EDIT.
package mocks
@ -46,6 +46,27 @@ func (_m *Artifact) GetData() ([]byte, error) {
return r0, r1
}
// Save provides a mock function with given fields: path
func (_m *Artifact) Save(path string) (bool, error) {
ret := _m.Called(path)
var r0 bool
if rf, ok := ret.Get(0).(func(string) bool); ok {
r0 = rf(path)
} else {
r0 = ret.Get(0).(bool)
}
var r1 error
if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(path)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// SaveToDir provides a mock function with given fields: dir
func (_m *Artifact) SaveToDir(dir string) (bool, error) {
ret := _m.Called(dir)