@@ -26,10 +26,16 @@ var _ = Describe("Patcher", func() {
26
26
)
27
27
28
28
BeforeEach (func () {
29
+ // 1. Create a temporary directory
29
30
var err error
30
31
tempDir , err = os .MkdirTemp ("" , "patcher-tests" )
31
32
Expect (err ).NotTo (HaveOccurred ())
32
33
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
33
39
originalFile , err = os .CreateTemp (tempDir , "original-*" )
34
40
Expect (err ).NotTo (HaveOccurred ())
35
41
@@ -63,7 +69,7 @@ This is the original file.
63
69
err = os .WriteFile (patchFile .Name (), []byte (patchContent ), 0644 )
64
70
Expect (err ).NotTo (HaveOccurred ())
65
71
66
- err = Patch (tempDir , patchFile .Name ())
72
+ err = Patch (patchFile .Name ())
67
73
Expect (err ).NotTo (HaveOccurred ())
68
74
69
75
patchedContent , err := os .ReadFile (originalFile .Name ())
@@ -93,7 +99,7 @@ This is the original file.
93
99
err = os .WriteFile (patchFile .Name (), []byte (invalidPatchContent ), 0644 )
94
100
Expect (err ).NotTo (HaveOccurred ())
95
101
96
- err = Patch (tempDir , patchFile .Name ())
102
+ err = Patch (patchFile .Name ())
97
103
Expect (err ).To (HaveOccurred ())
98
104
Expect (strings .Contains (err .Error (), "patch command failed" )).To (BeTrue ())
99
105
})
@@ -118,7 +124,7 @@ This is the original file.
118
124
err = os .WriteFile (patchFile .Name (), []byte (patchContent ), 0644 )
119
125
Expect (err ).NotTo (HaveOccurred ())
120
126
121
- err = Patch (tempDir , patchFile .Name ())
127
+ err = Patch (patchFile .Name ())
122
128
Expect (err ).NotTo (HaveOccurred ())
123
129
124
130
patchedContent , err := os .ReadFile (originalFile .Name ())
@@ -146,7 +152,7 @@ This is the original file.
146
152
err = os .WriteFile (patchFile .Name (), []byte (patchContent ), 0644 )
147
153
Expect (err ).NotTo (HaveOccurred ())
148
154
149
- err = Patch (tempDir , patchFile .Name ())
155
+ err = Patch (patchFile .Name ())
150
156
Expect (err ).NotTo (HaveOccurred ())
151
157
152
158
patchedContent , err := os .ReadFile (originalFile .Name ())
0 commit comments