@@ -133,11 +133,14 @@ func TestFolderCreationTracker_directoryExists(t *testing.T) {
133133 existsIdx := JpptFolderIndex {0 , 1 }
134134 folderCreated := "folderCreated"
135135 createdIdx := JpptFolderIndex {1 , 1 } // cheap validation of job part overlap
136+ folderShouldCreate := "folderShouldCreate"
137+ shouldCreateIdx := JpptFolderIndex {0 , 2 }
136138
137139 plan := & mockedJobPlan {
138140 transfers : map [JpptFolderIndex ]* JobPartPlanTransfer {
139- existsIdx : {atomicTransferStatus : common .ETransferStatus .NotStarted ()},
140- createdIdx : {atomicTransferStatus : common .ETransferStatus .NotStarted ()},
141+ existsIdx : {atomicTransferStatus : common .ETransferStatus .NotStarted ()},
142+ createdIdx : {atomicTransferStatus : common .ETransferStatus .NotStarted ()},
143+ shouldCreateIdx : {atomicTransferStatus : common .ETransferStatus .NotStarted ()},
141144 },
142145 }
143146
@@ -149,20 +152,28 @@ func TestFolderCreationTracker_directoryExists(t *testing.T) {
149152
150153 fct .RegisterPropertiesTransfer (folderExists , existsIdx .PartNum , existsIdx .TransferIndex )
151154 fct .RegisterPropertiesTransfer (folderCreated , createdIdx .PartNum , createdIdx .TransferIndex )
155+ fct .RegisterPropertiesTransfer (folderShouldCreate , shouldCreateIdx .PartNum , shouldCreateIdx .TransferIndex )
152156
153157 _ = fct .CreateFolder (folderCreated , func () error {
154158 return nil
155159 }) // "create" our folder
156160 err := fct .CreateFolder (folderExists , func () error {
157- return common.FolderCreationErrorFolderAlreadyExists {}
158- })
159- a .NoError (err , "already exists should be caught" )
161+ return common.FolderCreationErrorAlreadyExists {}
162+ }) // fail creation on not existing
163+ a .NoError (err , "already exists should be caught" ) // ensure we caught that error
164+ expectedFailureErr := errors .New ("this creation should fail" )
165+ err = fct .CreateFolder (folderShouldCreate , func () error {
166+ return expectedFailureErr
167+ }) // ensure that a natural failure should return properly
168+ a .Equal (err , expectedFailureErr )
160169
161170 // validate folder states
162- a .Equal (fct .contents [folderCreated ].Status , EJpptFolderTrackerStatus .FolderCreated ())
171+ a .Equal (fct .contents [folderCreated ].Status , EJpptFolderTrackerStatus .FolderCreated ()) // Our created folder should be marked as such.
163172 a .Equal (plan .transfers [createdIdx ].TransferStatus (), common .ETransferStatus .FolderCreated ())
164- a .Equal (fct .contents [folderExists ].Status , EJpptFolderTrackerStatus .FolderExisted ())
173+ a .Equal (fct .contents [folderExists ].Status , EJpptFolderTrackerStatus .FolderExisted ()) // Our existing folder should be marked as such.
165174 a .Equal (plan .transfers [existsIdx ].TransferStatus (), common .ETransferStatus .FolderExisted ())
175+ a .Equal (fct .contents [folderShouldCreate ].Status , EJpptFolderTrackerStatus .Unseen ()) // no status updates should've occurred on a "naturally" failed create.
176+ a .Equal (plan .transfers [shouldCreateIdx ].TransferStatus (), common .ETransferStatus .NotStarted ())
166177
167178 // validate that re-create doesn't trigger on either
168179 err = fct .CreateFolder (folderCreated , func () error {
@@ -175,4 +186,9 @@ func TestFolderCreationTracker_directoryExists(t *testing.T) {
175186 return errors .New ("should return nil" )
176187 })
177188 a .NoError (err )
189+
190+ // validate we can still create normally for our naturally failed folder
191+ err = fct .CreateFolder (folderShouldCreate , func () error {
192+ return nil
193+ })
178194}
0 commit comments