github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/verify-distribution/verifydistribution/verify_distribution_test.go (about) 1 // Copyright (c) 2022, 2023, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package verifydistribution 5 6 import ( 7 "bufio" 8 "fmt" 9 "os" 10 "path/filepath" 11 "regexp" 12 13 "github.com/onsi/gomega" 14 . "github.com/verrazzano/verrazzano/pkg/files" 15 "github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework" 16 "github.com/verrazzano/verrazzano/tools/vz/pkg/helpers" 17 ) 18 19 const SLASH = string(filepath.Separator) 20 21 const verrazzanoPrefix = "verrazzano-" 22 23 const liteDistribution = "Lite" 24 25 var variant string 26 var vzDevVersion string 27 28 var allPaths = map[string]string{ 29 "top": "", 30 "bin": SLASH + "bin", 31 "images": SLASH + "images", 32 "manifests": SLASH + "manifests", 33 "profiles": SLASH + "manifests" + SLASH + "profiles", 34 "k8s": SLASH + "manifests" + SLASH + "k8s", 35 } 36 37 var opensourcefileslistbydir = map[string][]string{ 38 "top": {"LICENSE", "README.md", "bin", "manifests"}, 39 "bin": {"bom_utils.sh", "vz", "vz-registry-image-helper.sh"}, 40 "manifests": {"charts", "k8s", "profiles", "verrazzano-bom.json"}, 41 "k8s": {"verrazzano-platform-operator.yaml"}, 42 "profiles": {"dev.yaml", "managed-cluster.yaml", "none.yaml", "prod.yaml"}, 43 } 44 45 var fullBundleFileslistbydir = map[string][]string{ 46 "top": {"LICENSE", "README.md", "README.html", "bin", "images", "manifests"}, 47 "bin": {"bom_utils.sh", "darwin-amd64", "darwin-arm64", "linux-amd64", "linux-arm64", "vz-registry-image-helper.sh"}, 48 "vz": {"vz"}, 49 "manifests": {"charts", "k8s", "profiles", "verrazzano-bom.json"}, 50 "k8s": {"verrazzano-platform-operator.yaml"}, 51 "profiles": {"dev.yaml", "managed-cluster.yaml", "none.yaml", "prod.yaml"}, 52 } 53 54 var t = framework.NewTestFramework("verifydistribution") 55 56 var _ = t.Describe("Verify VZ distribution", func() { 57 58 variant = os.Getenv("DISTRIBUTION_VARIANT") 59 generatedPath := os.Getenv("TARBALL_DIR") 60 tarballRootDir := os.Getenv("TARBALL_ROOT_DIR") 61 repoPath := os.Getenv("GO_REPO_PATH") 62 63 if variant == liteDistribution { 64 t.Describe("When provided Lite ", func() { 65 66 vzDevVersion = os.Getenv("VERRAZZANO_DEV_VERSION") 67 vzPrefix := verrazzanoPrefix + vzDevVersion 68 var liteBundleZipContents = []string{ 69 "verrazzano-platform-operator.yaml", "verrazzano-platform-operator.yaml.sha256", vzPrefix, 70 vzPrefix + "-darwin-amd64.tar.gz", vzPrefix + "-darwin-amd64.tar.gz.sha256", 71 vzPrefix + "-darwin-arm64.tar.gz", vzPrefix + "-darwin-arm64.tar.gz.sha256", 72 vzPrefix + "-linux-amd64.tar.gz", vzPrefix + "-linux-amd64.tar.gz.sha256", 73 vzPrefix + "-linux-arm64.tar.gz", vzPrefix + "-linux-arm64.tar.gz.sha256", 74 } 75 t.It("Verify lite bundle zip contents", func() { 76 filesList := []string{} 77 filesInfo, err := os.ReadDir(tarballRootDir) 78 if err != nil { 79 println(err.Error()) 80 } 81 gomega.Expect(err).To(gomega.BeNil()) 82 for _, each := range filesInfo { 83 filesList = append(filesList, each.Name()) 84 } 85 gomega.Expect(filesList).Should(gomega.ConsistOf(liteBundleZipContents)) 86 }) 87 88 t.It("Verify Lite bundle extracted contents", func() { 89 verifyDistributionByDirectory(generatedPath+allPaths["top"], "top", variant) 90 verifyDistributionByDirectory(generatedPath+allPaths["bin"], "bin", variant) 91 verifyDistributionByDirectory(generatedPath+allPaths["manifests"], "manifests", variant) 92 verifyDistributionByDirectory(generatedPath+allPaths["k8s"], "k8s", variant) 93 verifyDistributionByDirectory(generatedPath+allPaths["profiles"], "profiles", variant) 94 }) 95 }) 96 } else { 97 t.Describe("When provided full bundle", func() { 98 t.It("Verify Full Bundle", func() { 99 verifyDistributionByDirectory(generatedPath+allPaths["top"], "top", variant) 100 verifyDistributionByDirectory(generatedPath+allPaths["bin"], "bin", variant) 101 102 verifyDistributionByDirectory(generatedPath+allPaths["bin"]+"/darwin-amd64", "vz", variant) 103 verifyDistributionByDirectory(generatedPath+allPaths["bin"]+"/darwin-arm64", "vz", variant) 104 verifyDistributionByDirectory(generatedPath+allPaths["bin"]+"/linux-amd64", "vz", variant) 105 verifyDistributionByDirectory(generatedPath+allPaths["bin"]+"/linux-arm64", "vz", variant) 106 107 verifyDistributionByDirectory(generatedPath+allPaths["manifests"], "manifests", variant) 108 verifyDistributionByDirectory(generatedPath+allPaths["k8s"], "k8s", variant) 109 verifyDistributionByDirectory(generatedPath+allPaths["profiles"], "profiles", variant) 110 }) 111 }) 112 113 t.Describe("Verify that images matches with BOM file for the Full bundle", func() { 114 t.It("Verify images", func() { 115 116 regexRegistry := regexp.MustCompile(`.*.io/`) 117 regexSemi := regexp.MustCompile(`:`) 118 regexRegistry2 := regexp.MustCompile(`.*.io_`) 119 regexUndersc := regexp.MustCompile(`_`) 120 regexTar := regexp.MustCompile(`.tar`) 121 122 componentsList := []string{} 123 file, err := os.OpenFile(tarballRootDir+"/componentsList.txt", os.O_RDONLY, 0644) 124 if err != nil { 125 println(err.Error()) 126 } 127 gomega.Expect(err).To(gomega.BeNil()) 128 129 scanner := bufio.NewScanner(file) 130 for scanner.Scan() { 131 eachName := scanner.Text() 132 eachName = regexRegistry.ReplaceAllString(eachName, "") 133 eachName = regexSemi.ReplaceAllString(eachName, "-") 134 componentsList = append(componentsList, eachName) 135 } 136 componentsList = helpers.RemoveDuplicate(componentsList) 137 138 imagesList := []string{} 139 imagesInfo, err2 := os.ReadDir(generatedPath + allPaths["images"]) 140 if err2 != nil { 141 println(err2.Error()) 142 } 143 gomega.Expect(err2).To(gomega.BeNil()) 144 for _, each := range imagesInfo { 145 eachName := each.Name() 146 eachName = regexRegistry2.ReplaceAllString(eachName, "") 147 eachName = regexUndersc.ReplaceAllString(eachName, "/") 148 eachName = regexTar.ReplaceAllString(eachName, "") 149 imagesList = append(imagesList, eachName) 150 } 151 gomega.Expect(imagesList).Should(gomega.ConsistOf(componentsList)) 152 }) 153 }) 154 } 155 156 t.Describe("Verify charts for common", func() { 157 t.It("Verify charts for both Lite and Full bundle", func() { 158 var re1 = regexp.MustCompile(".*/verrazzano-platform-operator/") 159 sourcesLocation := repoPath + "/verrazzano/platform-operator/helm_config/charts/verrazzano-platform-operator/" 160 sourcesFilesList, _ := GetMatchingFiles(sourcesLocation, regexp.MustCompile(".*")) 161 sourcesFilesFilteredList := []string{} 162 for _, each := range sourcesFilesList { 163 eachName := re1.ReplaceAllString(each, "") 164 sourcesFilesFilteredList = append(sourcesFilesFilteredList, eachName) 165 } 166 chartsLocationZip := generatedPath + "/manifests/charts/verrazzano-platform-operator/" 167 chartsFilesList, _ := GetMatchingFiles(chartsLocationZip, regexp.MustCompile(".*")) 168 chartsFilesListFiltered := []string{} 169 for _, each := range chartsFilesList { 170 eachName := re1.ReplaceAllString(each, "") 171 chartsFilesListFiltered = append(chartsFilesListFiltered, eachName) 172 } 173 gomega.Expect(sourcesFilesFilteredList).Should(gomega.ConsistOf(chartsFilesListFiltered)) 174 }) 175 }) 176 }) 177 178 // verifyDistributionByDirectory verifies the contents of inputDir with Values from map 179 func verifyDistributionByDirectory(inputDir string, key string, variant string) { 180 fmt.Printf("Input DIR provided is: %s, key provided: %s, Variant provided: %s", inputDir, key, variant) 181 filesList := []string{} 182 filesInfo, err := os.ReadDir(inputDir) 183 if err != nil { 184 println(err.Error()) 185 } 186 gomega.Expect(err).To(gomega.BeNil()) 187 for _, each := range filesInfo { 188 filesList = append(filesList, each.Name()) 189 } 190 if variant == liteDistribution { 191 fmt.Println("Provided variant is: ", variant) 192 gomega.Expect(filesList).Should(gomega.ConsistOf(opensourcefileslistbydir[key])) 193 } else { 194 fmt.Println("Provided variant is: Full") 195 gomega.Expect(filesList).Should(gomega.ConsistOf(fullBundleFileslistbydir[key])) 196 } 197 fmt.Printf("All files found for %s \n", key) 198 }