@@ -19,7 +19,6 @@ package native_test
19
19
import (
20
20
"fmt"
21
21
"io"
22
- "io/ioutil"
23
22
"os"
24
23
"path/filepath"
25
24
"strings"
@@ -50,27 +49,22 @@ func testNativeImage(t *testing.T, context spec.G, it spec.S) {
50
49
)
51
50
52
51
it .Before (func () {
53
- var err error
54
-
55
- ctx .Application .Path , err = ioutil .TempDir ("" , "native-image-application" )
56
- Expect (err ).NotTo (HaveOccurred ())
57
-
58
- ctx .Layers .Path , err = ioutil .TempDir ("" , "native-image-layers" )
59
- Expect (err ).NotTo (HaveOccurred ())
52
+ ctx .Application .Path = t .TempDir ()
53
+ ctx .Layers .Path = t .TempDir ()
60
54
61
55
executor = & mocks.Executor {}
62
56
63
57
props = properties .NewProperties ()
64
58
65
- _ , _ , err = props .Set ("Start-Class" , "test-start-class" )
59
+ _ , _ , err : = props .Set ("Start-Class" , "test-start-class" )
66
60
Expect (err ).NotTo (HaveOccurred ())
67
61
_ , _ , err = props .Set ("Class-Path" , "manifest-class-path" )
68
62
Expect (err ).NotTo (HaveOccurred ())
69
63
70
- Expect (ioutil .WriteFile (filepath .Join (ctx .Application .Path , "fixture-marker" ), []byte {}, 0644 )).To (Succeed ())
64
+ Expect (os .WriteFile (filepath .Join (ctx .Application .Path , "fixture-marker" ), []byte {}, 0644 )).To (Succeed ())
71
65
Expect (os .MkdirAll (filepath .Join (ctx .Application .Path , "BOOT-INF" ), 0755 )).To (Succeed ())
72
66
Expect (os .MkdirAll (filepath .Join (ctx .Application .Path , "META-INF" ), 0755 )).To (Succeed ())
73
- Expect (ioutil .WriteFile (filepath .Join (ctx .Application .Path , "META-INF" , "MANIFEST.MF" ), []byte {}, 0644 )).To (Succeed ())
67
+ Expect (os .WriteFile (filepath .Join (ctx .Application .Path , "META-INF" , "MANIFEST.MF" ), []byte {}, 0644 )).To (Succeed ())
74
68
75
69
nativeImage , err = native .NewNativeImage (ctx .Application .Path , "test-argument-1 test-argument-2" , "" , "none" , "" , props , ctx .StackID )
76
70
nativeImage .Logger = bard .NewLogger (io .Discard )
@@ -91,7 +85,9 @@ func testNativeImage(t *testing.T, context spec.G, it spec.S) {
91
85
})).Run (func (args mock.Arguments ) {
92
86
exec := args .Get (0 ).(effect.Execution )
93
87
lastArg := exec .Args [len (exec .Args )- 1 ]
94
- Expect (ioutil .WriteFile (filepath .Join (layer .Path , lastArg ), []byte {}, 0644 )).To (Succeed ())
88
+ Expect (os .WriteFile (filepath .Join (layer .Path , lastArg ), []byte {}, 0755 )).To (Succeed ())
89
+ Expect (os .WriteFile (filepath .Join (layer .Path , "libawt.so" ), []byte {}, 0644 )).To (Succeed ())
90
+ Expect (os .WriteFile (filepath .Join (layer .Path , "libawt_headless.so" ), []byte {}, 0644 )).To (Succeed ())
95
91
}).Return (nil )
96
92
97
93
executor .On ("Execute" , mock .MatchedBy (func (e effect.Execution ) bool {
@@ -100,7 +96,9 @@ func testNativeImage(t *testing.T, context spec.G, it spec.S) {
100
96
})).Run (func (args mock.Arguments ) {
101
97
exec := args .Get (0 ).(effect.Execution )
102
98
lastArg := exec .Args [len (exec .Args )- 1 ]
103
- Expect (ioutil .WriteFile (filepath .Join (layer .Path , lastArg ), []byte {}, 0644 )).To (Succeed ())
99
+ Expect (os .WriteFile (filepath .Join (layer .Path , lastArg ), []byte {}, 0755 )).To (Succeed ())
100
+ Expect (os .WriteFile (filepath .Join (layer .Path , "libawt.so" ), []byte {}, 0644 )).To (Succeed ())
101
+ Expect (os .WriteFile (filepath .Join (layer .Path , "libawt_headless.so" ), []byte {}, 0644 )).To (Succeed ())
104
102
}).Return (nil )
105
103
106
104
layer , err = ctx .Layers .Layer ("test-layer" )
@@ -134,6 +132,25 @@ func testNativeImage(t *testing.T, context spec.G, it spec.S) {
134
132
"-cp" , "some-classpath" ,
135
133
"test-start-class" ,
136
134
}))
135
+
136
+ Expect (filepath .Join (ctx .Application .Path , "BOOT-INF" )).ToNot (BeADirectory ())
137
+ Expect (filepath .Join (ctx .Application .Path , "META-INF" )).ToNot (BeADirectory ())
138
+
139
+ Expect (filepath .Join (layer .Path , "test-start-class" )).To (BeARegularFile ())
140
+ Expect (filepath .Join (layer .Path , "libawt.so" )).To (BeARegularFile ())
141
+ Expect (filepath .Join (layer .Path , "libawt_headless.so" )).To (BeARegularFile ())
142
+
143
+ info , err := os .Stat (filepath .Join (layer .Path , "test-start-class" ))
144
+ Expect (err ).NotTo (HaveOccurred ())
145
+ fmt .Println ("info.Mode().Perm(): " , info .Mode ().Perm ().String ())
146
+ Expect (info .Mode ().Perm ()).To (Equal (os .FileMode (0755 )))
147
+
148
+ Expect (filepath .Join (ctx .Application .Path , "test-start-class" )).To (BeARegularFile ())
149
+ Expect (filepath .Join (ctx .Application .Path , "libawt.so" )).To (BeARegularFile ())
150
+ Expect (filepath .Join (ctx .Application .Path , "libawt_headless.so" )).To (BeARegularFile ())
151
+ info , err = os .Stat (filepath .Join (ctx .Application .Path , "test-start-class" ))
152
+ Expect (err ).NotTo (HaveOccurred ())
153
+ Expect (info .Mode ().Perm ()).To (Equal (os .FileMode (0755 )))
137
154
})
138
155
})
139
156
@@ -160,7 +177,7 @@ func testNativeImage(t *testing.T, context spec.G, it spec.S) {
160
177
it ("contributes native image with Class-Path from manifest and args from a file" , func () {
161
178
argsFile := filepath .Join (ctx .Application .Path , "target" , "args.txt" )
162
179
Expect (os .MkdirAll (filepath .Join (ctx .Application .Path , "target" ), 0755 )).To (Succeed ())
163
- Expect (ioutil .WriteFile (argsFile , []byte (`test-argument-1 test-argument-2` ), 0644 )).To (Succeed ())
180
+ Expect (os .WriteFile (argsFile , []byte (`test-argument-1 test-argument-2` ), 0644 )).To (Succeed ())
164
181
165
182
nativeImage , err := native .NewNativeImage (ctx .Application .Path , "" , argsFile , "none" , "" , props , ctx .StackID )
166
183
nativeImage .Logger = bard .NewLogger (io .Discard )
@@ -209,7 +226,7 @@ func testNativeImage(t *testing.T, context spec.G, it spec.S) {
209
226
})).Run (func (args mock.Arguments ) {
210
227
exec := args .Get (0 ).(effect.Execution )
211
228
lastArg := exec .Args [len (exec .Args )- 1 ]
212
- Expect (ioutil .WriteFile (filepath .Join (layer .Path , lastArg ), []byte {}, 0644 )).To (Succeed ())
229
+ Expect (os .WriteFile (filepath .Join (layer .Path , lastArg ), []byte {}, 0644 )).To (Succeed ())
213
230
}).Return (nil )
214
231
215
232
layer , err = ctx .Layers .Layer ("test-layer" )
@@ -254,7 +271,7 @@ func testNativeImage(t *testing.T, context spec.G, it spec.S) {
254
271
})).Run (func (args mock.Arguments ) {
255
272
exec := args .Get (0 ).(effect.Execution )
256
273
lastArg := exec .Args [len (exec .Args )- 1 ]
257
- Expect (ioutil .WriteFile (filepath .Join (layer .Path , lastArg ), []byte {}, 0644 )).To (Succeed ())
274
+ Expect (os .WriteFile (filepath .Join (layer .Path , lastArg ), []byte {}, 0644 )).To (Succeed ())
258
275
}).Return (nil )
259
276
260
277
layer , err = ctx .Layers .Layer ("test-layer" )
@@ -316,7 +333,7 @@ func testNativeImage(t *testing.T, context spec.G, it spec.S) {
316
333
executor .On ("Execute" , mock .MatchedBy (func (e effect.Execution ) bool {
317
334
return e .Command == "upx"
318
335
})).Run (func (args mock.Arguments ) {
319
- Expect (ioutil .WriteFile (filepath .Join (layer .Path , "test-start-class" ), []byte ("upx-compressed" ), 0644 )).To (Succeed ())
336
+ Expect (os .WriteFile (filepath .Join (layer .Path , "test-start-class" ), []byte ("upx-compressed" ), 0644 )).To (Succeed ())
320
337
}).Return (nil )
321
338
322
339
_ , err := nativeImage .Contribute (layer )
@@ -331,7 +348,7 @@ func testNativeImage(t *testing.T, context spec.G, it spec.S) {
331
348
bin := filepath .Join (layer .Path , "test-start-class" )
332
349
Expect (bin ).To (BeARegularFile ())
333
350
334
- data , err := ioutil .ReadFile (bin )
351
+ data , err := os .ReadFile (bin )
335
352
Expect (err ).ToNot (HaveOccurred ())
336
353
Expect (data ).To (ContainSubstring ("upx-compressed" ))
337
354
})
@@ -344,8 +361,8 @@ func testNativeImage(t *testing.T, context spec.G, it spec.S) {
344
361
executor .On ("Execute" , mock .MatchedBy (func (e effect.Execution ) bool {
345
362
return e .Command == "gzexe"
346
363
})).Run (func (args mock.Arguments ) {
347
- Expect (ioutil .WriteFile (filepath .Join (layer .Path , "test-start-class" ), []byte ("gzexe-compressed" ), 0644 )).To (Succeed ())
348
- Expect (ioutil .WriteFile (filepath .Join (layer .Path , "test-start-class~" ), []byte ("original" ), 0644 )).To (Succeed ())
364
+ Expect (os .WriteFile (filepath .Join (layer .Path , "test-start-class" ), []byte ("gzexe-compressed" ), 0644 )).To (Succeed ())
365
+ Expect (os .WriteFile (filepath .Join (layer .Path , "test-start-class~" ), []byte ("original" ), 0644 )).To (Succeed ())
349
366
}).Return (nil )
350
367
351
368
_ , err := nativeImage .Contribute (layer )
@@ -360,7 +377,7 @@ func testNativeImage(t *testing.T, context spec.G, it spec.S) {
360
377
bin := filepath .Join (layer .Path , "test-start-class" )
361
378
Expect (bin ).To (BeARegularFile ())
362
379
363
- data , err := ioutil .ReadFile (bin )
380
+ data , err := os .ReadFile (bin )
364
381
Expect (err ).ToNot (HaveOccurred ())
365
382
Expect (data ).To (ContainSubstring ("gzexe-compressed" ))
366
383
Expect (filepath .Join (layer .Path , "test-start-class~" )).ToNot (BeAnExistingFile ())
@@ -373,7 +390,7 @@ func testNativeImage(t *testing.T, context spec.G, it spec.S) {
373
390
})
374
391
375
392
it ("contributes a static native image executable with dynamic libc" , func () {
376
- Expect (ioutil .WriteFile (filepath .Join (ctx .Application .Path , "BOOT-INF" , "classpath.idx" ), []byte (`
393
+ Expect (os .WriteFile (filepath .Join (ctx .Application .Path , "BOOT-INF" , "classpath.idx" ), []byte (`
377
394
- "test-jar.jar"
378
395
- "spring-graalvm-native-0.8.6-xxxxxx.jar"
379
396
` ), 0644 )).To (Succeed ())
0 commit comments