@@ -50,7 +50,7 @@ func TestPublishCratesSuccess(t *testing.T) {
5050 }
5151 lastTag := "release-2001-02-03"
5252
53- if err := PublishCrates (t .Context (), cfg , true , false , lastTag , files ); err != nil {
53+ if err := publishCrates (t .Context (), cfg , true , false , lastTag , files ); err != nil {
5454 t .Fatal (err )
5555 }
5656}
@@ -85,7 +85,7 @@ func TestPublishCratesWithNewCrate(t *testing.T) {
8585 path .Join ("src" , "pubsub" , "src" , "lib.rs" ),
8686 }
8787 lastTag := "release-with-new-crate"
88- if err := PublishCrates (t .Context (), cfg , true , false , lastTag , files ); err != nil {
88+ if err := publishCrates (t .Context (), cfg , true , false , lastTag , files ); err != nil {
8989 t .Fatal (err )
9090 }
9191}
@@ -119,7 +119,7 @@ func TestPublishCratesWithRootsPem(t *testing.T) {
119119 path .Join ("src" , "storage" , "src" , "lib.rs" ),
120120 }
121121 lastTag := "release-with-roots-pem"
122- if err := PublishCrates (t .Context (), cfg , true , false , lastTag , files ); err != nil {
122+ if err := publishCrates (t .Context (), cfg , true , false , lastTag , files ); err != nil {
123123 t .Fatal (err )
124124 }
125125}
@@ -158,7 +158,7 @@ func TestPublishCratesWithBadManifest(t *testing.T) {
158158 path .Join ("src" , "storage" , "src" , "lib.rs" ),
159159 }
160160 lastTag := "release-2001-02-03"
161- if err := PublishCrates (t .Context (), cfg , true , false , lastTag , files ); err == nil {
161+ if err := publishCrates (t .Context (), cfg , true , false , lastTag , files ); err == nil {
162162 t .Errorf ("expected an error with a bad manifest file" )
163163 }
164164}
@@ -180,7 +180,7 @@ func TestPublishCratesGetPlanError(t *testing.T) {
180180 path .Join ("src" , "storage" , "src" , "lib.rs" ),
181181 }
182182 lastTag := "release-2001-02-03"
183- if err := PublishCrates (t .Context (), cfg , true , false , lastTag , files ); err == nil {
183+ if err := publishCrates (t .Context (), cfg , true , false , lastTag , files ); err == nil {
184184 t .Fatalf ("expected an error during plan generation" )
185185 }
186186}
@@ -209,7 +209,7 @@ func TestPublishCratesPlanMismatchError(t *testing.T) {
209209 path .Join ("src" , "storage" , "src" , "lib.rs" ),
210210 }
211211 lastTag := "release-2001-02-03"
212- if err := PublishCrates (t .Context (), cfg , true , false , lastTag , files ); err == nil {
212+ if err := publishCrates (t .Context (), cfg , true , false , lastTag , files ); err == nil {
213213 t .Fatalf ("expected an error during plan comparison" )
214214 }
215215}
254254 lastTag := "release-2001-02-03"
255255
256256 // This should fail because semver-checks fails.
257- if err := PublishCrates (t .Context (), cfg , true , false , lastTag , files ); err == nil {
257+ if err := publishCrates (t .Context (), cfg , true , false , lastTag , files ); err == nil {
258258 t .Fatal ("expected an error from semver-checks" )
259259 }
260260 // Skipping the checks should succeed.
261- if err := PublishCrates (t .Context (), cfg , true , true , lastTag , files ); err != nil {
261+ if err := publishCrates (t .Context (), cfg , true , true , lastTag , files ); err != nil {
262262 t .Fatal (err )
263263 }
264264}
265+
266+ func TestPublishSuccess (t * testing.T ) {
267+ testhelper .RequireCommand (t , "git" )
268+ testhelper .RequireCommand (t , "/bin/echo" )
269+ cfg := & config.Release {
270+ Remote : "origin" ,
271+ Branch : "main" ,
272+ Preinstalled : map [string ]string {
273+ "git" : "git" ,
274+ "cargo" : "/bin/echo" ,
275+ },
276+ Tools : map [string ][]config.Tool {
277+ "cargo" : {
278+ {Name : "cargo-semver-checks" , Version : "1.2.3" },
279+ {Name : "cargo-workspaces" , Version : "3.4.5" },
280+ },
281+ },
282+ }
283+ remoteDir := testhelper .SetupRepoWithChange (t , "release-2001-02-03" )
284+ testhelper .CloneRepository (t , remoteDir )
285+
286+ if err := Publish (t .Context (), cfg , true , false ); err != nil {
287+ t .Fatal (err )
288+ }
289+ }
290+
291+ func TestPublishWithLocalChangesError (t * testing.T ) {
292+ testhelper .RequireCommand (t , "git" )
293+ testhelper .RequireCommand (t , "/bin/echo" )
294+ config := & config.Release {
295+ Remote : "origin" ,
296+ Branch : "main" ,
297+ Preinstalled : map [string ]string {
298+ "git" : "git" ,
299+ "cargo" : "/bin/echo" ,
300+ },
301+ Tools : map [string ][]config.Tool {
302+ "cargo" : {
303+ {Name : "cargo-semver-checks" , Version : "1.2.3" },
304+ {Name : "cargo-workspaces" , Version : "3.4.5" },
305+ },
306+ },
307+ }
308+ remoteDir := testhelper .SetupRepoWithChange (t , "release-with-local-changes-error" )
309+ testhelper .CloneRepository (t , remoteDir )
310+ testhelper .AddCrate (t , path .Join ("src" , "pubsub" ), "google-cloud-pubsub" )
311+ if err := command .Run (t .Context (), "git" , "add" , path .Join ("src" , "pubsub" )); err != nil {
312+ t .Fatal (err )
313+ }
314+ if err := command .Run (t .Context (), "git" , "commit" , "-m" , "feat: created pubsub" , "." ); err != nil {
315+ t .Fatal (err )
316+ }
317+ if err := Publish (t .Context (), config , true , false ); err == nil {
318+ t .Errorf ("expected an error publishing with unpushed local commits" )
319+ }
320+ }
321+
322+ func TestPublishPreflightError (t * testing.T ) {
323+ config := & config.Release {
324+ Preinstalled : map [string ]string {
325+ "git" : "git-not-found" ,
326+ },
327+ }
328+ if err := Publish (t .Context (), config , true , false ); err == nil {
329+ t .Errorf ("expected a preflight error with a bad git command" )
330+ }
331+ }
332+
333+ func TestPublishLastTagError (t * testing.T ) {
334+ const echo = "/bin/echo"
335+ testhelper .RequireCommand (t , "git" )
336+ testhelper .RequireCommand (t , echo )
337+ config := config.Release {
338+ Remote : "origin" ,
339+ Branch : "invalid-branch" ,
340+ Preinstalled : map [string ]string {
341+ "cargo" : echo ,
342+ },
343+ }
344+ remoteDir := testhelper .SetupRepoWithChange (t , "release-2001-02-03" )
345+ testhelper .CloneRepository (t , remoteDir )
346+ if err := Publish (t .Context (), & config , true , false ); err == nil {
347+ t .Fatalf ("expected an error during GetLastTag" )
348+ }
349+ }
0 commit comments