@@ -27,22 +27,31 @@ func testChdir(t *testing.T, dir string) {
27
27
func TestInternalMeta (t * testing.T ) {
28
28
tmp := t .TempDir ()
29
29
testChdir (t , tmp )
30
- testWriteJSON (t , "meta.json" , JSONManifest {Entrypoint : "entry" })
31
30
packagesDir := filepath .Join (tmp , "packages" )
31
+
32
32
t .Run ("local-tarball" , func (t * testing.T ) {
33
33
mod := Module {
34
34
Type : ModuleTypeLocal ,
35
35
ExePath : filepath .Join (tmp , "whatever.tar.gz" ),
36
36
}
37
- exePath , err := mod .EvaluateExePath (packagesDir )
38
- test .That (t , err , test .ShouldBeNil )
39
- exeDir , err := mod .exeDir (packagesDir )
40
- test .That (t , err , test .ShouldBeNil )
41
- // "entry" is from meta.json.
42
- test .That (t , exePath , test .ShouldEqual , filepath .Join (exeDir , "entry" ))
37
+ t .Run ("meta.json missing" , func (t * testing.T ) {
38
+ _ , err := mod .EvaluateExePath (packagesDir )
39
+ test .That (t , err , test .ShouldEqual , errLocalTarballEntrypoint )
40
+ })
41
+
42
+ t .Run ("meta.json present" , func (t * testing.T ) {
43
+ exeDir , err := mod .exeDir (packagesDir )
44
+ test .That (t , err , test .ShouldBeNil )
45
+ manifest := JSONManifest {Entrypoint : "entry" }
46
+ testWriteJSON (t , filepath .Join (exeDir , "meta.json" ), manifest )
47
+ exePath , err := mod .EvaluateExePath (packagesDir )
48
+ test .That (t , err , test .ShouldBeNil )
49
+ test .That (t , exePath , test .ShouldResemble , filepath .Join (exeDir , manifest .Entrypoint ))
50
+ })
43
51
})
44
52
45
53
t .Run ("non-tarball" , func (t * testing.T ) {
54
+ testWriteJSON (t , "meta.json" , JSONManifest {Entrypoint : "entry" })
46
55
mod := Module {
47
56
Type : ModuleTypeLocal ,
48
57
ExePath : filepath .Join (tmp , "whatever" ),
@@ -94,11 +103,8 @@ func TestSyntheticModule(t *testing.T) {
94
103
testWriteJSON (t , filepath .Join (tmp , "meta.json" ), & meta )
95
104
96
105
// local tarball case
97
- syntheticPath , err := modNeedsSynthetic .EvaluateExePath (tmp )
98
- test .That (t , err , test .ShouldBeNil )
99
- exeDir , err := modNeedsSynthetic .exeDir (tmp )
100
- test .That (t , err , test .ShouldBeNil )
101
- test .That (t , syntheticPath , test .ShouldEqual , filepath .Join (exeDir , meta .Entrypoint ))
106
+ _ , err := modNeedsSynthetic .EvaluateExePath (tmp )
107
+ test .That (t , err , test .ShouldEqual , errLocalTarballEntrypoint )
102
108
103
109
// vanilla case
104
110
notTarPath , err := modNotTar .EvaluateExePath (tmp )
@@ -289,7 +295,6 @@ func TestGetJSONManifest(t *testing.T) {
289
295
290
296
exePath := filepath .Join (tmp , "module.tgz" )
291
297
exeDir := filepath .Dir (exePath )
292
- exeMetaJSONFilepath := filepath .Join (exeDir , "meta.json" )
293
298
unpackedModDir := filepath .Join (tmp , "unpacked-mod-dir" )
294
299
unpackedModMetaJSONFilepath := filepath .Join (unpackedModDir , "meta.json" )
295
300
env := map [string ]string {}
@@ -308,26 +313,6 @@ func TestGetJSONManifest(t *testing.T) {
308
313
test .That (t , err .Error (), test .ShouldContainSubstring , unpackedModDir )
309
314
test .That (t , err .Error (), test .ShouldContainSubstring , exeDir )
310
315
311
- // meta.json found in executable directory; parsing fails
312
- exeMetaJSONFile , err := os .Create (exeMetaJSONFilepath )
313
- test .That (t , err , test .ShouldBeNil )
314
- defer exeMetaJSONFile .Close ()
315
-
316
- meta , moduleWorkingDirectory , err = modLocalTar .getJSONManifest (unpackedModDir , env )
317
- test .That (t , meta , test .ShouldBeNil )
318
- test .That (t , moduleWorkingDirectory , test .ShouldBeEmpty )
319
- test .That (t , err , test .ShouldNotBeNil )
320
- test .That (t , err .Error (), test .ShouldContainSubstring , "local tarball" )
321
- test .That (t , errors .Is (err , os .ErrNotExist ), test .ShouldBeFalse )
322
-
323
- // meta.json found in executable directory; parsing succeeds
324
- testWriteJSON (t , exeMetaJSONFilepath , validJSONManifest )
325
-
326
- meta , moduleWorkingDirectory , err = modLocalTar .getJSONManifest (unpackedModDir , env )
327
- test .That (t , * meta , test .ShouldResemble , validJSONManifest )
328
- test .That (t , moduleWorkingDirectory , test .ShouldEqual , exeDir )
329
- test .That (t , err , test .ShouldBeNil )
330
-
331
316
// meta.json found in unpacked modular directory; parsing fails
332
317
unpackedModMetaJSONFile , err := os .Create (unpackedModMetaJSONFilepath )
333
318
test .That (t , err , test .ShouldBeNil )
@@ -425,6 +410,8 @@ func TestMergeEnvVars(t *testing.T) {
425
410
// testWriteJSON is a t.Helper that serializes `value` to `path` as json.
426
411
func testWriteJSON (t * testing.T , path string , value any ) {
427
412
t .Helper ()
413
+ err := os .MkdirAll (filepath .Dir (path ), 0o700 )
414
+ test .That (t , err , test .ShouldBeNil )
428
415
file , err := os .Create (path )
429
416
test .That (t , err , test .ShouldBeNil )
430
417
defer file .Close ()
0 commit comments