@@ -805,11 +805,7 @@ func TestStartNextStay_DoNotWriteLastModifiedFileInCommit_WhenFileIsDeleted(t *t
805
805
next (configuration )
806
806
807
807
start (configuration )
808
- file1Path := filepath .Join (workingDir , "file1.txt" )
809
- err := os .Remove (file1Path )
810
- if err != nil {
811
- failWithFailure (t , "no error" , fmt .Sprintf ("error %v occured deleting file %s" , err , file1Path ))
812
- }
808
+ removeFile (t , filepath .Join (workingDir , "file1.txt" ))
813
809
next (configuration )
814
810
815
811
assertOnBranch (t , "mob-session" )
@@ -826,12 +822,7 @@ func TestStartNextStay_DoNotWriteLastModifiedFileInCommit_WhenFileIsMoved(t *tes
826
822
827
823
start (configuration )
828
824
createDirectory (t , "dir" )
829
- oldPath := filepath .Join (workingDir , "file1.txt" )
830
- newPath := filepath .Join (workingDir , "dir" , "file1.txt" )
831
- err := os .Rename (oldPath , newPath )
832
- if err != nil {
833
- failWithFailure (t , "no error" , fmt .Sprintf ("error %v occured moving %s to %s" , err , oldPath , newPath ))
834
- }
825
+ moveFile (t , filepath .Join (workingDir , "file1.txt" ), filepath .Join (workingDir , "dir" , "file1.txt" ))
835
826
next (configuration )
836
827
837
828
assertOnBranch (t , "mob-session" )
@@ -865,12 +856,7 @@ func TestRunOutput(t *testing.T) {
865
856
setWorkingDir (tempDir + "/local" )
866
857
start (configuration )
867
858
createFile (t , "file1.txt" , "asdf" )
868
- outputFile := filepath .Join (tempDir , "local" , "file1.txt" )
869
- content , err := os .ReadFile (outputFile )
870
- if err != nil {
871
- failWithFailure (t , "no error" , fmt .Sprintf ("error %v occured reading %s" , err , outputFile ))
872
- }
873
- output := string (content )
859
+ output := readFile (t , filepath .Join (tempDir , "local" , "file1.txt" ))
874
860
assertOutputContains (t , & output , "asdf" )
875
861
}
876
862
@@ -1771,6 +1757,29 @@ func createDirectoryInPath(t *testing.T, path, directory string) (pathToFile str
1771
1757
return
1772
1758
}
1773
1759
1760
+ func removeFile (t * testing.T , path string ) {
1761
+ err := os .Remove (path )
1762
+ if err != nil {
1763
+ failWithFailure (t , "no error" , fmt .Sprintf ("error %v occured deleting file %s" , err , path ))
1764
+ }
1765
+ }
1766
+
1767
+ func moveFile (t * testing.T , oldPath string , newPath string ) {
1768
+ err := os .Rename (oldPath , newPath )
1769
+ if err != nil {
1770
+ failWithFailure (t , "no error" , fmt .Sprintf ("error %v occured moving %s to %s" , err , oldPath , newPath ))
1771
+ }
1772
+ }
1773
+
1774
+ func readFile (t * testing.T , path string ) string {
1775
+ content , err := os .ReadFile (path )
1776
+ if err != nil {
1777
+ failWithFailure (t , "no error" , fmt .Sprintf ("reading file %s failed with %v" , path , err ))
1778
+ }
1779
+ output := string (content )
1780
+ return output
1781
+ }
1782
+
1774
1783
func assertOnBranch (t * testing.T , branch string ) {
1775
1784
currentBranch := gitCurrentBranch ()
1776
1785
if currentBranch .Name != branch {
0 commit comments