@@ -26,10 +26,16 @@ var _ = Describe("Patcher", func() {
2626 )
2727
2828 BeforeEach (func () {
29+ // 1. Create a temporary directory
2930 var err error
3031 tempDir , err = os .MkdirTemp ("" , "patcher-tests" )
3132 Expect (err ).NotTo (HaveOccurred ())
3233
34+ // 2. Change the working directory to the temporary directory
35+ err = os .Chdir (tempDir )
36+ Expect (err ).NotTo (HaveOccurred ())
37+
38+ // 3. Create the original file and the patch file
3339 originalFile , err = os .CreateTemp (tempDir , "original-*" )
3440 Expect (err ).NotTo (HaveOccurred ())
3541
@@ -63,7 +69,7 @@ This is the original file.
6369 err = os .WriteFile (patchFile .Name (), []byte (patchContent ), 0644 )
6470 Expect (err ).NotTo (HaveOccurred ())
6571
66- err = Patch (tempDir , patchFile .Name ())
72+ err = Patch (patchFile .Name ())
6773 Expect (err ).NotTo (HaveOccurred ())
6874
6975 patchedContent , err := os .ReadFile (originalFile .Name ())
@@ -93,7 +99,7 @@ This is the original file.
9399 err = os .WriteFile (patchFile .Name (), []byte (invalidPatchContent ), 0644 )
94100 Expect (err ).NotTo (HaveOccurred ())
95101
96- err = Patch (tempDir , patchFile .Name ())
102+ err = Patch (patchFile .Name ())
97103 Expect (err ).To (HaveOccurred ())
98104 Expect (strings .Contains (err .Error (), "patch command failed" )).To (BeTrue ())
99105 })
@@ -118,7 +124,7 @@ This is the original file.
118124 err = os .WriteFile (patchFile .Name (), []byte (patchContent ), 0644 )
119125 Expect (err ).NotTo (HaveOccurred ())
120126
121- err = Patch (tempDir , patchFile .Name ())
127+ err = Patch (patchFile .Name ())
122128 Expect (err ).NotTo (HaveOccurred ())
123129
124130 patchedContent , err := os .ReadFile (originalFile .Name ())
@@ -146,7 +152,7 @@ This is the original file.
146152 err = os .WriteFile (patchFile .Name (), []byte (patchContent ), 0644 )
147153 Expect (err ).NotTo (HaveOccurred ())
148154
149- err = Patch (tempDir , patchFile .Name ())
155+ err = Patch (patchFile .Name ())
150156 Expect (err ).NotTo (HaveOccurred ())
151157
152158 patchedContent , err := os .ReadFile (originalFile .Name ())
0 commit comments