5
5
package test
6
6
7
7
import (
8
+ "context"
8
9
"fmt"
9
10
"os"
10
11
"path/filepath"
11
12
"testing"
12
13
13
14
"github.com/stretchr/testify/require"
15
+
16
+ "github.com/zarf-dev/zarf/src/api/v1alpha1"
17
+ layout2 "github.com/zarf-dev/zarf/src/internal/packager2/layout"
14
18
)
15
19
16
20
func TestCreateTemplating (t * testing.T ) {
17
21
t .Log ("E2E: Create Templating" )
18
22
19
- // run `zarf package create` with a specified image cache location
20
- tmpdir := t .TempDir ()
21
- decompressPath := filepath .Join (tmpdir , ".package-decompressed" )
22
- sbomPath := filepath .Join (tmpdir , ".sbom-location" )
23
-
24
- pkgName := fmt .Sprintf ("zarf-package-templating-%s.tar.zst" , e2e .Arch )
23
+ sbomPath := t .TempDir ()
24
+ outPath := t .TempDir ()
25
+ templatingPath := filepath .Join (outPath , fmt .Sprintf ("zarf-package-templating-%s.tar.zst" , e2e .Arch ))
26
+ fileFoldersPath := filepath .Join (outPath , fmt .Sprintf ("zarf-package-file-folders-templating-sbom-%s.tar.zst" , e2e .Arch ))
25
27
26
28
// Test that not specifying a package variable results in an error
27
- _ , _ , err := e2e .Zarf (t , "package" , "create" , "src/test/packages/04-templating" , "--confirm" )
29
+ _ , _ , err := e2e .Zarf (t , "package" , "create" , "src/test/packages/04-templating" , "-o" , outPath , "- -confirm" )
28
30
require .Error (t , err )
29
31
30
32
// Test a simple package variable example with `--set` (will fail to pull an image if this is not set correctly)
31
- stdOut , stdErr , err := e2e .Zarf (t , "package" , "create" , "src/test/packages/04-templating" , "--set" , "PODINFO_VERSION=6.4.0" , "--confirm" )
32
- require .NoError (t , err , stdOut , stdErr )
33
-
34
- stdOut , stdErr , err = e2e .Zarf (t , "t" , "archiver" , "decompress" , pkgName , decompressPath , "--unarchive-all" )
35
- require .NoError (t , err , stdOut , stdErr )
33
+ _ , _ , err = e2e .Zarf (t , "package" , "create" , "src/test/packages/04-templating" , "-o" , outPath , "--set" , "PODINFO_VERSION=6.4.0" , "--confirm" )
34
+ require .NoError (t , err )
36
35
37
- // Check that the constant in the zarf.yaml is replaced correctly
38
- builtConfig , err := os .ReadFile (decompressPath + "/zarf.yaml" )
36
+ pkgLayout , err := layout2 .LoadFromTar (context .Background (), templatingPath , layout2.PackageLayoutOptions {})
39
37
require .NoError (t , err )
40
- require .Contains (t , string (builtConfig ), "name: PODINFO_VERSION\n value: 6.4.0" )
38
+ expectedConstant := v1alpha1.Constant {Name : "PODINFO_VERSION" , Value : "6.4.0" , Pattern : "^[\\ w\\ -\\ .]+$" }
39
+ require .Contains (t , pkgLayout .Pkg .Constants , expectedConstant )
41
40
42
41
// Test that files and file folders template and handle SBOMs correctly
43
- stdOut , stdErr , err = e2e .Zarf (t , "package" , "create" , "src/test/packages/04-file-folders-templating-sbom/" , "--sbom-out" , sbomPath , "--confirm" )
44
- require .NoError (t , err , stdOut , stdErr )
45
- require .Contains (t , stdErr , "Creating SBOMs for 0 images and 2 components with files." )
46
-
47
- fileFoldersPkgName := fmt .Sprintf ("zarf-package-file-folders-templating-sbom-%s.tar.zst" , e2e .Arch )
48
-
49
- // Deploy the package and look for the variables in the output
50
- stdOut , stdErr , err = e2e .Zarf (t , "package" , "deploy" , fileFoldersPkgName , "--set" , "DOGGO=doggy" , "--set" , "KITTEH=meowza" , "--set" , "PANDA=pandemonium" , "--confirm" )
51
- require .NoError (t , err , stdOut , stdErr )
52
- require .Contains (t , stdErr , "A doggy barks!" )
53
- require .Contains (t , stdErr , " - meowza" )
54
- require .Contains (t , stdErr , "# Total pandemonium" )
42
+ _ , _ , err = e2e .Zarf (t , "package" , "create" , "src/test/packages/04-file-folders-templating-sbom/" , "-o" , outPath , "--sbom-out" , sbomPath , "--confirm" )
43
+ require .NoError (t , err )
55
44
56
45
// Ensure that the `requirements.txt` files are discovered correctly
57
46
require .FileExists (t , filepath .Join (sbomPath , "file-folders-templating-sbom" , "compare.html" ))
@@ -65,5 +54,20 @@ func TestCreateTemplating(t *testing.T) {
65
54
require .NoError (t , err )
66
55
require .Contains (t , string (filesJSON ), "pandas" )
67
56
68
- e2e .CleanFiles (t , pkgName , fileFoldersPkgName )
57
+ // Deploy the package and look for the variables in the output
58
+ workingPath := t .TempDir ()
59
+ _ , _ , err = e2e .ZarfInDir (t , workingPath , "package" , "deploy" , fileFoldersPath , "--set" , "DOGGO=doggy" , "--set" , "KITTEH=meowza" , "--set" , "PANDA=pandemonium" , "--confirm" )
60
+ require .NoError (t , err )
61
+
62
+ b , err := os .ReadFile (filepath .Join (workingPath , "temp" , "requirements.txt" ))
63
+ require .NoError (t , err )
64
+ require .Equal (t , "# Total pandemonium\n pandas==1.5.0\n " , string (b ))
65
+
66
+ b , err = os .ReadFile (filepath .Join (workingPath , "temp" , "include-files" , "simple.txt" ))
67
+ require .NoError (t , err )
68
+ require .Equal (t , "A doggy barks!\n " , string (b ))
69
+
70
+ b , err = os .ReadFile (filepath .Join (workingPath , "temp" , "include-files" , "something.yaml" ))
71
+ require .NoError (t , err )
72
+ require .Equal (t , "something:\n - a\n - meowza\n - meows\n " , string (b ))
69
73
}
0 commit comments