11package avancement
22
33import (
4- "testing"
4+ "errors"
5+ "path"
56 "path/filepath"
67 "strings"
7- "path "
8+ "testing "
89
910 "github.com/jenkins-x/go-scm/scm"
1011 fakescm "github.com/jenkins-x/go-scm/scm/driver/fake"
@@ -29,17 +30,16 @@ func TestPromoteWithSuccessKeepCacheFalse(t *testing.T) {
2930func promoteWithSuccess (t * testing.T , keepCache bool ) {
3031 dstBranch := "test-branch"
3132 author := & git.
Author {
Name :
"Testing User" ,
Email :
"[email protected] " ,
Token :
"test-token" }
32- client , _ := fakescm .NewDefault ()
33- fakeClientFactory := func (s string ) * scm.Client {
34- return client
35- }
3633 devRepo , stagingRepo := mock .New ("/dev" , "master" ), mock .New ("/staging" , "master" )
3734 repos := map [string ]* mock.Repository {
3835 mustAddCredentials (t , dev , author ): devRepo ,
3936 mustAddCredentials (t , staging , author ): stagingRepo ,
4037 }
4138 sm := New ("tmp" , author )
42- sm .clientFactory = fakeClientFactory
39+ sm .clientFactory = func (s string ) * scm.Client {
40+ client , _ := fakescm .NewDefault ()
41+ return client
42+ }
4343 sm .repoFactory = func (url , _ string , _ bool ) (git.Repo , error ) {
4444 return git .Repo (repos [url ]), nil
4545 }
@@ -75,20 +75,19 @@ func TestPromoteLocalWithSuccessKeepCacheTrue(t *testing.T) {
7575func promoteLocalWithSuccess (t * testing.T , keepCache bool ) {
7676 dstBranch := "test-branch"
7777 author := & git.
Author {
Name :
"Testing User" ,
Email :
"[email protected] " ,
Token :
"test-token" }
78- client , _ := fakescm .NewDefault ()
79- fakeClientFactory := func (s string ) * scm.Client {
80- return client
81- }
8278 stagingRepo := mock .New ("/staging" , "master" )
8379 devRepo := NewLocal ("/dev" )
8480
8581 sm := New ("tmp" , author )
86- sm .clientFactory = fakeClientFactory
82+ sm .clientFactory = func (s string ) * scm.Client {
83+ client , _ := fakescm .NewDefault ()
84+ return client
85+ }
8786 sm .repoFactory = func (url , _ string , _ bool ) (git.Repo , error ) {
8887 return git .Repo (stagingRepo ), nil
8988 }
90- sm .localFactory = func (path string , _ bool ) ( git.Source , error ) {
91- return git .Source (devRepo ), nil
89+ sm .localFactory = func (path string , _ bool ) git.Source {
90+ return git .Source (devRepo )
9291 }
9392 sm .debug = true
9493 devRepo .AddFiles ("/config/myfile.yaml" )
@@ -143,19 +142,19 @@ func mustAddCredentials(t *testing.T, repoURL string, a *git.Author) string {
143142}
144143
145144func TestPromoteWithCacheDeletionFailure (t * testing.T ) {
146- dstBranch := mock . FAIL_DELETING_REPO_BRANCH
145+ dstBranch := "test-branch"
147146 author := & git.
Author {
Name :
"Testing User" ,
Email :
"[email protected] " ,
Token :
"test-token" }
148- client , _ := fakescm .NewDefault ()
149- fakeClientFactory := func (s string ) * scm.Client {
150- return client
151- }
152147 devRepo , stagingRepo := mock .New ("/dev" , "master" ), mock .New ("/staging" , "master" )
148+ stagingRepo .DeleteErr = errors .New ("failed test delete" )
153149 repos := map [string ]* mock.Repository {
154150 mustAddCredentials (t , dev , author ): devRepo ,
155151 mustAddCredentials (t , staging , author ): stagingRepo ,
156152 }
157153 sm := New ("tmp" , author )
158- sm .clientFactory = fakeClientFactory
154+ sm .clientFactory = func (s string ) * scm.Client {
155+ client , _ := fakescm .NewDefault ()
156+ return client
157+ }
159158 sm .repoFactory = func (url , _ string , _ bool ) (git.Repo , error ) {
160159 return git .Repo (repos [url ]), nil
161160 }
@@ -175,7 +174,6 @@ func TestPromoteWithCacheDeletionFailure(t *testing.T) {
175174 devRepo .AssertDeletedFromCache (t )
176175}
177176
178-
179177type mockSource struct {
180178 files []string
181179 localPath string
@@ -193,11 +191,11 @@ func NewLocal(localPath string) *mockSource {
193191// and then calls filePath.Walk() on /full/path/to/repo/services/ .
194192// When CopyService() drives Walk(), 'base' is typically services/service-name
195193// Thus we take each /full/path/to/file/in/mockSource.files[] and split it at 'services/' as happens in the Walk() method we're mocking.
196- func (s * mockSource ) Walk (base string , cb func (string , string ) error ) error {
194+ func (s * mockSource ) Walk (_ string , cb func (string , string ) error ) error {
197195 if s .files == nil {
198196 return nil
199197 }
200- base = filepath .Join (s .localPath , "config" )
198+ base : = filepath .Join (s .localPath , "config" )
201199
202200 for _ , f := range s .files {
203201 splitString := filepath .Dir (base ) + "/"
0 commit comments