@@ -14,7 +14,15 @@ const (
1414 staging = "https://example.com/testing/staging-env"
1515)
1616
17- func TestPromoteWithSuccess (t * testing.T ) {
17+ func TestPromoteWithSuccessKeepCacheTrue (t * testing.T ) {
18+ promoteWithSuccess (t , true )
19+ }
20+
21+ func TestPromoteWithSuccessKeepCacheFalse (t * testing.T ) {
22+ promoteWithSuccess (t , false )
23+ }
24+
25+ func promoteWithSuccess (t * testing.T , keepCache bool ) {
1826 dstBranch := "test-branch"
1927 author := & git.
Author {
Name :
"Testing User" ,
Email :
"[email protected] " ,
Token :
"test-token" }
2028 client , _ := fakescm .NewDefault ()
@@ -33,7 +41,7 @@ func TestPromoteWithSuccess(t *testing.T) {
3341 }
3442 devRepo .AddFiles ("/services/my-service/base/config/myfile.yaml" )
3543
36- err := sm .Promote ("my-service" , dev , staging , dstBranch )
44+ err := sm .Promote ("my-service" , dev , staging , dstBranch , keepCache )
3745 if err != nil {
3846 t .Fatal (err )
3947 }
@@ -42,6 +50,14 @@ func TestPromoteWithSuccess(t *testing.T) {
4250 stagingRepo .AssertFileCopiedInBranch (t , dstBranch , "/dev/services/my-service/base/config/myfile.yaml" , "/staging/services/my-service/base/config/myfile.yaml" )
4351 stagingRepo .AssertCommit (t , dstBranch , defaultCommitMsg , author )
4452 stagingRepo .AssertPush (t , dstBranch )
53+
54+ if keepCache {
55+ stagingRepo .AssertNotDeletedFromCache (t )
56+ devRepo .AssertNotDeletedFromCache (t )
57+ } else {
58+ stagingRepo .AssertDeletedFromCache (t )
59+ devRepo .AssertDeletedFromCache (t )
60+ }
4561}
4662
4763func TestAddCredentials (t * testing.T ) {
@@ -75,3 +91,36 @@ func mustAddCredentials(t *testing.T, repoURL string, a *git.Author) string {
7591 }
7692 return u
7793}
94+
95+ func TestPromoteWithCacheDeletionFailure (t * testing.T ) {
96+ dstBranch := mock .FAIL_DELETING_REPO_BRANCH
97+ author := & git.
Author {
Name :
"Testing User" ,
Email :
"[email protected] " ,
Token :
"test-token" }
98+ client , _ := fakescm .NewDefault ()
99+ fakeClientFactory := func (s string ) * scm.Client {
100+ return client
101+ }
102+ devRepo , stagingRepo := mock .New ("/dev" , "master" ), mock .New ("/staging" , "master" )
103+ repos := map [string ]* mock.Repository {
104+ mustAddCredentials (t , dev , author ): devRepo ,
105+ mustAddCredentials (t , staging , author ): stagingRepo ,
106+ }
107+ sm := New ("tmp" , author )
108+ sm .clientFactory = fakeClientFactory
109+ sm .repoFactory = func (url , _ string , _ bool ) (git.Repo , error ) {
110+ return git .Repo (repos [url ]), nil
111+ }
112+ devRepo .AddFiles ("/services/my-service/base/config/myfile.yaml" )
113+
114+ err := sm .Promote ("my-service" , dev , staging , dstBranch , false )
115+ if err != nil {
116+ t .Fatal (err )
117+ }
118+
119+ stagingRepo .AssertBranchCreated (t , "master" , dstBranch )
120+ stagingRepo .AssertFileCopiedInBranch (t , dstBranch , "/dev/services/my-service/base/config/myfile.yaml" , "/staging/services/my-service/base/config/myfile.yaml" )
121+ stagingRepo .AssertCommit (t , dstBranch , defaultCommitMsg , author )
122+ stagingRepo .AssertPush (t , dstBranch )
123+
124+ stagingRepo .AssertNotDeletedFromCache (t )
125+ devRepo .AssertDeletedFromCache (t )
126+ }
0 commit comments