github.com/Racer159/jackal@v0.32.7-0.20240401174413-0bd2339e4f2e/src/test/e2e/10_component_flavor_test.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: 2021-Present The Jackal Authors 3 4 // Package test provides e2e tests for Jackal. 5 package test 6 7 import ( 8 "fmt" 9 "os" 10 "path/filepath" 11 "testing" 12 13 "github.com/stretchr/testify/require" 14 "github.com/stretchr/testify/suite" 15 ) 16 17 type FlavorSuite struct { 18 suite.Suite 19 *require.Assertions 20 } 21 22 var ( 23 flavorExample = filepath.Join("examples", "package-flavors") 24 flavorTest = filepath.Join("src", "test", "packages", "10-package-flavors") 25 flavorExamplePath string 26 flavorTestAMDPath = filepath.Join("build", "jackal-package-test-package-flavors-amd64.tar.zst") 27 flavorTestARMPath = filepath.Join("build", "jackal-package-test-package-flavors-arm64.tar.zst") 28 ) 29 30 func (suite *FlavorSuite) SetupSuite() { 31 suite.Assertions = require.New(suite.T()) 32 33 // Setup the example package path after e2e has been initialized 34 flavorExamplePath = filepath.Join("build", fmt.Sprintf("jackal-package-package-flavors-%s-1.0.0.tar.zst", e2e.Arch)) 35 } 36 37 func (suite *FlavorSuite) TearDownSuite() { 38 err := os.RemoveAll(flavorExamplePath) 39 suite.NoError(err) 40 err = os.RemoveAll(flavorTestAMDPath) 41 suite.NoError(err) 42 err = os.RemoveAll(flavorTestARMPath) 43 suite.NoError(err) 44 } 45 46 func (suite *FlavorSuite) Test_0_FlavorExample() { 47 suite.T().Log("E2E: Package Flavor Example") 48 49 _, stdErr, err := e2e.Jackal("package", "create", flavorExample, "-o", "build", "--flavor", "oracle-cookie-crunch", "--no-color", "--confirm") 50 suite.NoError(err) 51 52 // Ensure that the oracle image is included 53 suite.Contains(stdErr, `oraclelinux:9-slim`) 54 55 // Ensure that the common pod was included 56 suite.Contains(stdErr, `description: The pod that runs the specified flavor of Enterprise Linux`) 57 58 // Ensure that the other flavors are not included 59 suite.NotContains(stdErr, `rockylinux:9-minimal`) 60 suite.NotContains(stdErr, `almalinux:9-minimal`) 61 suite.NotContains(stdErr, `opensuse/leap:15`) 62 } 63 64 func (suite *FlavorSuite) Test_1_FlavorArchFiltering() { 65 suite.T().Log("E2E: Package Flavor + Arch Filtering") 66 67 _, stdErr, err := e2e.Jackal("package", "create", flavorTest, "-o", "build", "--flavor", "vanilla", "-a", "amd64", "--no-color", "--confirm") 68 suite.NoError(err) 69 70 // Ensure that the initial filter was applied 71 suite.Contains(stdErr, ` 72 - name: combined 73 description: vanilla-amd`) 74 75 // Ensure that the import filter was applied 76 suite.Contains(stdErr, ` 77 - name: via-import 78 description: vanilla-amd`) 79 80 // Ensure that the other flavors / architectures are not included 81 suite.NotContains(stdErr, `vanilla-arm`) 82 suite.NotContains(stdErr, `chocolate-amd`) 83 suite.NotContains(stdErr, `chocolate-arm`) 84 85 _, stdErr, err = e2e.Jackal("package", "create", flavorTest, "-o", "build", "--flavor", "chocolate", "-a", "amd64", "--no-color", "--confirm") 86 suite.NoError(err) 87 88 // Ensure that the initial filter was applied 89 suite.Contains(stdErr, ` 90 - name: combined 91 description: chocolate-amd`) 92 93 // Ensure that the import filter was applied 94 suite.Contains(stdErr, ` 95 - name: via-import 96 description: chocolate-amd`) 97 98 // Ensure that the other flavors / architectures are not included 99 suite.NotContains(stdErr, `vanilla-arm`) 100 suite.NotContains(stdErr, `vanilla-amd`) 101 suite.NotContains(stdErr, `chocolate-arm`) 102 103 _, stdErr, err = e2e.Jackal("package", "create", flavorTest, "-o", "build", "--flavor", "chocolate", "-a", "arm64", "--no-color", "--confirm") 104 suite.NoError(err) 105 106 // Ensure that the initial filter was applied 107 suite.Contains(stdErr, ` 108 - name: combined 109 description: chocolate-arm`) 110 111 // Ensure that the import filter was applied 112 suite.Contains(stdErr, ` 113 - name: via-import 114 description: chocolate-arm`) 115 116 // Ensure that the other flavors / architectures are not included 117 suite.NotContains(stdErr, `vanilla-arm`) 118 suite.NotContains(stdErr, `vanilla-amd`) 119 suite.NotContains(stdErr, `chocolate-amd`) 120 } 121 122 func TestFlavorSuite(t *testing.T) { 123 suite.Run(t, new(FlavorSuite)) 124 }