@@ -28,6 +28,97 @@ const (
2828 newLibRsContents = `pub fn hello() -> &'static str { "Hello World" }`
2929)
3030
31+ func TestMatchesBranchPointSuccess (t * testing.T ) {
32+ requireCommand (t , "git" )
33+ config := & config.Release {
34+ Remote : "origin" ,
35+ Branch : "main" ,
36+ }
37+ remoteDir := setupForPublish (t , "v1.0.0" )
38+ cloneRepository (t , remoteDir )
39+ if err := matchesBranchPoint (config ); err != nil {
40+ t .Fatal (err )
41+ }
42+ }
43+
44+ func TestMatchesBranchDiffError (t * testing.T ) {
45+ requireCommand (t , "git" )
46+ config := & config.Release {
47+ Remote : "origin" ,
48+ Branch : "not-a-valid-branch" ,
49+ }
50+ remoteDir := setupForPublish (t , "v1.0.0" )
51+ cloneRepository (t , remoteDir )
52+ if err := matchesBranchPoint (config ); err == nil {
53+ t .Errorf ("expected an error with an invalid branch" )
54+ }
55+ }
56+
57+ func TestMatchesDirtyCloneError (t * testing.T ) {
58+ requireCommand (t , "git" )
59+ config := & config.Release {
60+ Remote : "origin" ,
61+ Branch : "not-a-valid-branch" ,
62+ }
63+ remoteDir := setupForPublish (t , "v1.0.0" )
64+ cloneRepository (t , remoteDir )
65+ addCrate (t , path .Join ("src" , "pubsub" ), "google-cloud-pubsub" )
66+ if err := external .Run ("git" , "add" , path .Join ("src" , "pubsub" )); err != nil {
67+ t .Fatal (err )
68+ }
69+ if err := external .Run ("git" , "commit" , "-m" , "feat: created pubsub" , "." ); err != nil {
70+ t .Fatal (err )
71+ }
72+
73+ if err := matchesBranchPoint (config ); err == nil {
74+ t .Errorf ("expected an error with a dirty clone" )
75+ }
76+ }
77+
78+ func TestIsNewFile (t * testing.T ) {
79+ const wantTag = "new-file-success"
80+ release := config.Release {
81+ Remote : "origin" ,
82+ Branch : "main" ,
83+ Preinstalled : map [string ]string {},
84+ }
85+ setupForVersionBump (t , wantTag )
86+ existingName := path .Join ("src" , "storage" , "src" , "lib.rs" )
87+ if err := os .WriteFile (existingName , []byte (newLibRsContents ), 0644 ); err != nil {
88+ t .Fatal (err )
89+ }
90+ newName := path .Join ("src" , "storage" , "src" , "new.rs" )
91+ if err := os .WriteFile (newName , []byte (newLibRsContents ), 0644 ); err != nil {
92+ t .Fatal (err )
93+ }
94+ if err := external .Run ("git" , "add" , "." ); err != nil {
95+ t .Fatal (err )
96+ }
97+ if err := external .Run ("git" , "commit" , "-m" , "feat: changed storage" , "." ); err != nil {
98+ t .Fatal (err )
99+ }
100+ if isNewFile (& release , wantTag , existingName ) {
101+ t .Errorf ("file is not new but reported as such: %s" , existingName )
102+ }
103+ if ! isNewFile (& release , wantTag , newName ) {
104+ t .Errorf ("file is new but not reported as such: %s" , newName )
105+ }
106+ }
107+
108+ func TestIsNewFileDiffError (t * testing.T ) {
109+ const wantTag = "new-file-success"
110+ release := config.Release {
111+ Remote : "origin" ,
112+ Branch : "main" ,
113+ Preinstalled : map [string ]string {},
114+ }
115+ setupForVersionBump (t , wantTag )
116+ existingName := path .Join ("src" , "storage" , "src" , "lib.rs" )
117+ if isNewFile (& release , "invalid-tag" , existingName ) {
118+ t .Errorf ("diff errors should return false for isNewFile(): %s" , existingName )
119+ }
120+ }
121+
31122func TestFilesChangedSuccess (t * testing.T ) {
32123 const wantTag = "release-2001-02-03"
33124
0 commit comments