@@ -28,7 +28,6 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
28
28
layersDir string
29
29
planPath string
30
30
cnbDir string
31
- envCnbDir string
32
31
binaryPath string
33
32
exitHandler * fakes.ExitHandler
34
33
)
@@ -71,9 +70,6 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
71
70
cnbDir , err = os .MkdirTemp ("" , "cnb" )
72
71
Expect (err ).NotTo (HaveOccurred ())
73
72
74
- envCnbDir , err = os .MkdirTemp ("" , "envCnb" )
75
- Expect (err ).NotTo (HaveOccurred ())
76
-
77
73
bpTOML := []byte (`
78
74
api = "0.8"
79
75
[buildpack]
@@ -91,7 +87,6 @@ api = "0.8"
91
87
uri = "some-license-uri"
92
88
` )
93
89
Expect (os .WriteFile (filepath .Join (cnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
94
- Expect (os .WriteFile (filepath .Join (envCnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
95
90
96
91
binaryPath = filepath .Join (cnbDir , "bin" , "build" )
97
92
@@ -169,8 +164,6 @@ api = "0.4"
169
164
clear-env = false
170
165
` )
171
166
Expect (os .WriteFile (filepath .Join (cnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
172
- Expect (os .WriteFile (filepath .Join (envCnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
173
-
174
167
})
175
168
176
169
it ("updates the buildpack plan.toml with any changes" , func () {
@@ -338,7 +331,6 @@ api = "0.6"
338
331
clear-env = false
339
332
` )
340
333
Expect (os .WriteFile (filepath .Join (cnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
341
- Expect (os .WriteFile (filepath .Join (envCnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
342
334
})
343
335
344
336
it ("throws an error" , func () {
@@ -462,7 +454,7 @@ api = "0.6"
462
454
463
455
context ("when the CNB_BUILDPACK_DIR environment variable is set" , func () {
464
456
it .Before (func () {
465
- os .Setenv ("CNB_BUILDPACK_DIR" , envCnbDir )
457
+ os .Setenv ("CNB_BUILDPACK_DIR" , cnbDir )
466
458
})
467
459
468
460
it .After (func () {
@@ -476,10 +468,184 @@ api = "0.6"
476
468
context = ctx
477
469
478
470
return packit.BuildResult {}, nil
479
- }, packit .WithArgs ([]string {binaryPath , layersDir , platformDir , planPath }))
471
+ }, packit .WithArgs ([]string {"env-var-override" , layersDir , platformDir , planPath }))
472
+
473
+ Expect (context ).To (Equal (packit.BuildContext {
474
+ CNBPath : cnbDir ,
475
+ Platform : packit.Platform {
476
+ Path : platformDir ,
477
+ },
478
+ Stack : "some-stack" ,
479
+ WorkingDir : tmpDir ,
480
+ Plan : packit.BuildpackPlan {
481
+ Entries : []packit.BuildpackPlanEntry {
482
+ {
483
+ Name : "some-entry" ,
484
+ Metadata : map [string ]interface {}{
485
+ "version" : "some-version" ,
486
+ "some-key" : "some-value" ,
487
+ },
488
+ },
489
+ },
490
+ },
491
+ Layers : packit.Layers {
492
+ Path : layersDir ,
493
+ },
494
+ BuildpackInfo : packit.BuildpackInfo {
495
+ ID : "some-id" ,
496
+ Name : "some-name" ,
497
+ Version : "some-version" ,
498
+ Homepage : "some-homepage" ,
499
+ Description : "some-description" ,
500
+ Keywords : []string {"some-keyword" },
501
+ SBOMFormats : []string {"some-sbom-format" , "some-other-sbom-format" },
502
+ Licenses : []packit.BuildpackInfoLicense {
503
+ {
504
+ Type : "some-license-type" ,
505
+ URI : "some-license-uri" ,
506
+ },
507
+ },
508
+ },
509
+ }))
510
+ })
511
+ })
512
+
513
+ context ("when the CNB_LAYERS_DIR environment variable is set" , func () {
514
+ it .Before (func () {
515
+ os .Setenv ("CNB_LAYERS_DIR" , layersDir )
516
+ })
517
+
518
+ it .After (func () {
519
+ os .Unsetenv ("CNB_LAYERS_DIR" )
520
+ })
521
+
522
+ it ("sets the correct value for layers dir in the Build context" , func () {
523
+ var context packit.BuildContext
524
+
525
+ packit .Build (func (ctx packit.BuildContext ) (packit.BuildResult , error ) {
526
+ context = ctx
527
+
528
+ return packit.BuildResult {}, nil
529
+ }, packit .WithArgs ([]string {binaryPath , "env-var-override" , platformDir , planPath }))
530
+
531
+ Expect (context ).To (Equal (packit.BuildContext {
532
+ CNBPath : cnbDir ,
533
+ Platform : packit.Platform {
534
+ Path : platformDir ,
535
+ },
536
+ Stack : "some-stack" ,
537
+ WorkingDir : tmpDir ,
538
+ Plan : packit.BuildpackPlan {
539
+ Entries : []packit.BuildpackPlanEntry {
540
+ {
541
+ Name : "some-entry" ,
542
+ Metadata : map [string ]interface {}{
543
+ "version" : "some-version" ,
544
+ "some-key" : "some-value" ,
545
+ },
546
+ },
547
+ },
548
+ },
549
+ Layers : packit.Layers {
550
+ Path : layersDir ,
551
+ },
552
+ BuildpackInfo : packit.BuildpackInfo {
553
+ ID : "some-id" ,
554
+ Name : "some-name" ,
555
+ Version : "some-version" ,
556
+ Homepage : "some-homepage" ,
557
+ Description : "some-description" ,
558
+ Keywords : []string {"some-keyword" },
559
+ SBOMFormats : []string {"some-sbom-format" , "some-other-sbom-format" },
560
+ Licenses : []packit.BuildpackInfoLicense {
561
+ {
562
+ Type : "some-license-type" ,
563
+ URI : "some-license-uri" ,
564
+ },
565
+ },
566
+ },
567
+ }))
568
+ })
569
+ })
570
+
571
+ context ("when the CNB_PLATFORM_DIR environment variable is set" , func () {
572
+ it .Before (func () {
573
+ os .Setenv ("CNB_PLATFORM_DIR" , platformDir )
574
+ })
575
+
576
+ it .After (func () {
577
+ os .Unsetenv ("CNB_PLATFORM_DIR" )
578
+ })
579
+
580
+ it ("sets the correct value for platform dir in the Build context" , func () {
581
+ var context packit.BuildContext
582
+
583
+ packit .Build (func (ctx packit.BuildContext ) (packit.BuildResult , error ) {
584
+ context = ctx
585
+
586
+ return packit.BuildResult {}, nil
587
+ }, packit .WithArgs ([]string {binaryPath , layersDir , "env-var-override" , planPath }))
588
+
589
+ Expect (context ).To (Equal (packit.BuildContext {
590
+ CNBPath : cnbDir ,
591
+ Platform : packit.Platform {
592
+ Path : platformDir ,
593
+ },
594
+ Stack : "some-stack" ,
595
+ WorkingDir : tmpDir ,
596
+ Plan : packit.BuildpackPlan {
597
+ Entries : []packit.BuildpackPlanEntry {
598
+ {
599
+ Name : "some-entry" ,
600
+ Metadata : map [string ]interface {}{
601
+ "version" : "some-version" ,
602
+ "some-key" : "some-value" ,
603
+ },
604
+ },
605
+ },
606
+ },
607
+ Layers : packit.Layers {
608
+ Path : layersDir ,
609
+ },
610
+ BuildpackInfo : packit.BuildpackInfo {
611
+ ID : "some-id" ,
612
+ Name : "some-name" ,
613
+ Version : "some-version" ,
614
+ Homepage : "some-homepage" ,
615
+ Description : "some-description" ,
616
+ Keywords : []string {"some-keyword" },
617
+ SBOMFormats : []string {"some-sbom-format" , "some-other-sbom-format" },
618
+ Licenses : []packit.BuildpackInfoLicense {
619
+ {
620
+ Type : "some-license-type" ,
621
+ URI : "some-license-uri" ,
622
+ },
623
+ },
624
+ },
625
+ }))
626
+ })
627
+ })
628
+
629
+ context ("when the CNB_BP_PLAN_PATH environment variable is set" , func () {
630
+ it .Before (func () {
631
+ os .Setenv ("CNB_BP_PLAN_PATH" , planPath )
632
+ })
633
+
634
+ it .After (func () {
635
+ os .Unsetenv ("CNB_BP_PLAN_PATH" )
636
+ })
637
+
638
+ it ("sets the correct value for platform dir in the Build context" , func () {
639
+ var context packit.BuildContext
640
+
641
+ packit .Build (func (ctx packit.BuildContext ) (packit.BuildResult , error ) {
642
+ context = ctx
643
+
644
+ return packit.BuildResult {}, nil
645
+ }, packit .WithArgs ([]string {binaryPath , layersDir , platformDir , "env-var-override" }))
480
646
481
647
Expect (context ).To (Equal (packit.BuildContext {
482
- CNBPath : envCnbDir ,
648
+ CNBPath : cnbDir ,
483
649
Platform : packit.Platform {
484
650
Path : platformDir ,
485
651
},
@@ -515,6 +681,18 @@ api = "0.6"
515
681
},
516
682
},
517
683
}))
684
+
685
+ contents , err := os .ReadFile (planPath )
686
+ Expect (err ).NotTo (HaveOccurred ())
687
+
688
+ Expect (string (contents )).To (MatchTOML (`
689
+ [[entries]]
690
+ name = "some-entry"
691
+
692
+ [entries.metadata]
693
+ version = "some-version"
694
+ some-key = "some-value"
695
+ ` ))
518
696
})
519
697
})
520
698
@@ -557,7 +735,6 @@ api = "0.6"
557
735
clear-env = false
558
736
` )
559
737
Expect (os .WriteFile (filepath .Join (cnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
560
- Expect (os .WriteFile (filepath .Join (envCnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
561
738
})
562
739
563
740
it ("throws an error" , func () {
@@ -622,7 +799,6 @@ api = "0.4"
622
799
clear-env = false
623
800
` )
624
801
Expect (os .WriteFile (filepath .Join (cnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
625
- Expect (os .WriteFile (filepath .Join (envCnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
626
802
})
627
803
628
804
it ("throws an error" , func () {
@@ -686,8 +862,6 @@ api = "0.4"
686
862
clear-env = false
687
863
` )
688
864
Expect (os .WriteFile (filepath .Join (cnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
689
- Expect (os .WriteFile (filepath .Join (envCnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
690
-
691
865
})
692
866
693
867
it ("throws an error" , func () {
@@ -750,7 +924,6 @@ api = "0.6"
750
924
clear-env = false
751
925
` )
752
926
Expect (os .WriteFile (filepath .Join (cnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
753
- Expect (os .WriteFile (filepath .Join (envCnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
754
927
})
755
928
756
929
it ("throws an error" , func () {
@@ -1168,7 +1341,6 @@ api = "0.5"
1168
1341
clear-env = false
1169
1342
` )
1170
1343
Expect (os .WriteFile (filepath .Join (cnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
1171
- Expect (os .WriteFile (filepath .Join (envCnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
1172
1344
Expect (os .Chmod (planPath , 0444 )).To (Succeed ())
1173
1345
})
1174
1346
@@ -1241,7 +1413,6 @@ api = "0.4"
1241
1413
clear-env = false
1242
1414
` )
1243
1415
Expect (os .WriteFile (filepath .Join (cnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
1244
- Expect (os .WriteFile (filepath .Join (envCnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
1245
1416
Expect (os .Chmod (planPath , 0444 )).To (Succeed ())
1246
1417
})
1247
1418
@@ -1332,7 +1503,6 @@ api = "0.4"
1332
1503
clear-env = false
1333
1504
` )
1334
1505
Expect (os .WriteFile (filepath .Join (cnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
1335
- Expect (os .WriteFile (filepath .Join (envCnbDir , "buildpack.toml" ), bpTOML , 0600 )).To (Succeed ())
1336
1506
Expect (os .Chmod (planPath , 0444 )).To (Succeed ())
1337
1507
})
1338
1508
0 commit comments