@@ -19,11 +19,98 @@ import (
19
19
"bytes"
20
20
"github.com/skyscanner/turbolift/internal/git"
21
21
"github.com/skyscanner/turbolift/internal/github"
22
+ "github.com/skyscanner/turbolift/internal/prompt"
22
23
"github.com/skyscanner/turbolift/internal/testsupport"
23
24
"github.com/stretchr/testify/assert"
24
25
"testing"
25
26
)
26
27
28
+ func TestItWarnsIfDescriptionFileTemplateIsUnchanged (t * testing.T ) {
29
+ fakeGitHub := github .NewAlwaysFailsFakeGitHub ()
30
+ gh = fakeGitHub
31
+ fakeGit := git .NewAlwaysSucceedsFakeGit ()
32
+ g = fakeGit
33
+ fakePrompt := prompt .NewFakePromptNo ()
34
+ p = fakePrompt
35
+
36
+ testsupport .PrepareTempCampaign (true , "org/repo1" , "org/repo2" )
37
+ testsupport .UseDefaultPrDescription ()
38
+
39
+ out , err := runCommand ()
40
+ assert .NoError (t , err )
41
+ assert .NotContains (t , out , "Creating PR in org/repo1" )
42
+ assert .NotContains (t , out , "Creating PR in org/repo2" )
43
+ assert .NotContains (t , out , "turbolift create-prs completed" )
44
+ assert .NotContains (t , out , "2 OK, 0 skipped" )
45
+
46
+ fakePrompt .AssertCalledWith (t , "It looks like the PR title and/or description may not have been updated in README.md. Are you sure you want to proceed?" )
47
+ }
48
+
49
+ func TestItWarnsIfOnlyPrTitleIsUnchanged (t * testing.T ) {
50
+ fakeGitHub := github .NewAlwaysFailsFakeGitHub ()
51
+ gh = fakeGitHub
52
+ fakeGit := git .NewAlwaysSucceedsFakeGit ()
53
+ g = fakeGit
54
+ fakePrompt := prompt .NewFakePromptNo ()
55
+ p = fakePrompt
56
+
57
+ testsupport .PrepareTempCampaign (true , "org/repo1" , "org/repo2" )
58
+ testsupport .UsePrTitleTodoOnly ()
59
+
60
+ out , err := runCommand ()
61
+ assert .NoError (t , err )
62
+ assert .NotContains (t , out , "Creating PR in org/repo1" )
63
+ assert .NotContains (t , out , "Creating PR in org/repo2" )
64
+ assert .NotContains (t , out , "turbolift create-prs completed" )
65
+ assert .NotContains (t , out , "2 OK, 0 skipped" )
66
+
67
+ fakePrompt .AssertCalledWith (t , "It looks like the PR title and/or description may not have been updated in README.md. Are you sure you want to proceed?" )
68
+ }
69
+
70
+ func TestItWarnsIfOnlyPrBodyIsUnchanged (t * testing.T ) {
71
+ fakeGitHub := github .NewAlwaysFailsFakeGitHub ()
72
+ gh = fakeGitHub
73
+ fakeGit := git .NewAlwaysSucceedsFakeGit ()
74
+ g = fakeGit
75
+ fakePrompt := prompt .NewFakePromptNo ()
76
+ p = fakePrompt
77
+
78
+ testsupport .PrepareTempCampaign (true , "org/repo1" , "org/repo2" )
79
+ testsupport .UsePrBodyTodoOnly ()
80
+
81
+ out , err := runCommand ()
82
+ assert .NoError (t , err )
83
+ assert .NotContains (t , out , "Creating PR in org/repo1" )
84
+ assert .NotContains (t , out , "Creating PR in org/repo2" )
85
+ assert .NotContains (t , out , "turbolift create-prs completed" )
86
+ assert .NotContains (t , out , "2 OK, 0 skipped" )
87
+
88
+ fakePrompt .AssertCalledWith (t , "It looks like the PR title and/or description may not have been updated in README.md. Are you sure you want to proceed?" )
89
+ }
90
+
91
+ func TestItWarnsIfDescriptionFileIsEmpty (t * testing.T ) {
92
+ fakeGitHub := github .NewAlwaysFailsFakeGitHub ()
93
+ gh = fakeGitHub
94
+ fakeGit := git .NewAlwaysSucceedsFakeGit ()
95
+ g = fakeGit
96
+ fakePrompt := prompt .NewFakePromptNo ()
97
+ p = fakePrompt
98
+
99
+ customDescriptionFileName := "custom.md"
100
+
101
+ testsupport .PrepareTempCampaign (true , "org/repo1" , "org/repo2" )
102
+ testsupport .CreateOrUpdatePrDescriptionFile (customDescriptionFileName , "" , "" )
103
+
104
+ out , err := runCommandWithAlternativeDescriptionFile (customDescriptionFileName )
105
+ assert .NoError (t , err )
106
+ assert .NotContains (t , out , "Creating PR in org/repo1" )
107
+ assert .NotContains (t , out , "Creating PR in org/repo2" )
108
+ assert .NotContains (t , out , "turbolift create-prs completed" )
109
+ assert .NotContains (t , out , "2 OK, 0 skipped" )
110
+
111
+ fakePrompt .AssertCalledWith (t , "It looks like the PR title and/or description may not have been updated in custom.md. Are you sure you want to proceed?" )
112
+ }
113
+
27
114
func TestItLogsCreatePrErrorsButContinuesToTryAll (t * testing.T ) {
28
115
fakeGitHub := github .NewAlwaysFailsFakeGitHub ()
29
116
gh = fakeGitHub
@@ -106,6 +193,31 @@ func TestItLogsCreateDraftPr(t *testing.T) {
106
193
})
107
194
}
108
195
196
+ func TestItCreatesPrsFromAlternativeDescriptionFile (t * testing.T ) {
197
+ fakeGitHub := github .NewAlwaysSucceedsFakeGitHub ()
198
+ gh = fakeGitHub
199
+ fakeGit := git .NewAlwaysSucceedsFakeGit ()
200
+ g = fakeGit
201
+
202
+ customDescriptionFileName := "custom.md"
203
+
204
+ testsupport .PrepareTempCampaign (true , "org/repo1" , "org/repo2" )
205
+ testsupport .CreateOrUpdatePrDescriptionFile (customDescriptionFileName , "custom PR title" , "custom PR body" )
206
+
207
+ out , err := runCommandWithAlternativeDescriptionFile (customDescriptionFileName )
208
+ assert .NoError (t , err )
209
+ assert .Contains (t , out , "Reading campaign data (repos.txt, custom.md)" )
210
+ assert .Contains (t , out , "Creating PR in org/repo1" )
211
+ assert .Contains (t , out , "Creating PR in org/repo2" )
212
+ assert .Contains (t , out , "turbolift create-prs completed" )
213
+ assert .Contains (t , out , "2 OK, 0 skipped" )
214
+
215
+ fakeGitHub .AssertCalledWith (t , [][]string {
216
+ {"work/org/repo1" , "custom PR title" },
217
+ {"work/org/repo2" , "custom PR title" },
218
+ })
219
+ }
220
+
109
221
func runCommand () (string , error ) {
110
222
cmd := NewCreatePRsCmd ()
111
223
outBuffer := bytes .NewBufferString ("" )
@@ -118,6 +230,19 @@ func runCommand() (string, error) {
118
230
return outBuffer .String (), nil
119
231
}
120
232
233
+ func runCommandWithAlternativeDescriptionFile (fileName string ) (string , error ) {
234
+ cmd := NewCreatePRsCmd ()
235
+ prDescriptionFile = fileName
236
+ outBuffer := bytes .NewBufferString ("" )
237
+ cmd .SetOut (outBuffer )
238
+ err := cmd .Execute ()
239
+
240
+ if err != nil {
241
+ return outBuffer .String (), err
242
+ }
243
+ return outBuffer .String (), nil
244
+ }
245
+
121
246
func runCommandDraft () (string , error ) {
122
247
cmd := NewCreatePRsCmd ()
123
248
isDraft = true
0 commit comments