github.com/SAP/cloud-mta-build-tool@v1.2.27/cmd/init_test.go (about) 1 package commands 2 3 import ( 4 "bytes" 5 "os" 6 "os/exec" 7 8 dir "github.com/SAP/cloud-mta-build-tool/internal/archive" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 ) 12 13 var _ = Describe("Init", func() { 14 15 BeforeEach(func() { 16 Ω(os.MkdirAll(getTestPath("result"), os.ModePerm)).Should(Succeed()) 17 }) 18 AfterEach(func() { 19 Ω(os.RemoveAll(getTestPath("result"))).Should(Succeed()) 20 }) 21 It("Sanity", func() { 22 initCmdSrc = getTestPath("mta") 23 initCmdTrg = getTestPath("result") 24 initCmd.Run(nil, []string{}) 25 Ω(getTestPath("result", "Makefile.mta")).Should(BeAnExistingFile()) 26 }) 27 }) 28 29 var _ = Describe("Build", func() { 30 BeforeEach(func() { 31 mbtCmdCLI = getBuildCmdCli() 32 }) 33 AfterEach(func() { 34 mbtCmdCLI = "" 35 }) 36 It("Success - build with abs source parameter", func() { 37 source := "\"" + getTestPath("mta") + "\"" 38 39 var stdout bytes.Buffer 40 cmd := exec.Command("bash", "-c", mbtCmdCLI+" build"+" --source "+source) 41 cmd.Stdout = &stdout 42 43 Ω(cmd.Run()).Should(Succeed()) 44 Ω(os.RemoveAll(getTestPath("mta", dir.MtarFolder))).Should(Succeed()) 45 }) 46 It("Success - build with relative source parameter", func() { 47 // Notice: relative source path is relative to os.Getwd() 48 source := "\"" + "testdata/mta" + "\"" 49 50 var stdout bytes.Buffer 51 cmd := exec.Command("bash", "-c", mbtCmdCLI+" build"+" --source "+source) 52 cmd.Stdout = &stdout 53 54 Ω(cmd.Run()).Should(Succeed()) 55 Ω(os.RemoveAll(getTestPath("mta", dir.MtarFolder))).Should(Succeed()) 56 }) 57 It("Success - build with abs source and abs target parameter", func() { 58 source := "\"" + getTestPath("mta") + "\"" 59 target := "\"" + getTestPath("mtar_result") + "\"" 60 61 var stdout bytes.Buffer 62 cmd := exec.Command("bash", "-c", mbtCmdCLI+" build"+" --source "+source+" --target "+target) 63 cmd.Stdout = &stdout 64 65 Ω(cmd.Run()).Should(Succeed()) 66 Ω(os.RemoveAll(getTestPath("mtar_result"))).Should(Succeed()) 67 }) 68 It("Success - build with abs source and relative target path parameter", func() { 69 // Notice: target parameter is relative to source parameter 70 source := "\"" + getTestPath("mta") + "\"" 71 target := "\"" + "mtar_result" + "\"" 72 73 var stdout bytes.Buffer 74 cmd := exec.Command("bash", "-c", mbtCmdCLI+" build"+" --source "+source+" --target "+target) 75 cmd.Stdout = &stdout 76 77 Ω(cmd.Run()).Should(Succeed()) 78 Ω(os.RemoveAll(getTestPath("mta", "mtar_result"))).Should(Succeed()) 79 }) 80 It("Success - build with relative source and abs target path parameter", func() { 81 source := "\"" + "testdata/mta" + "\"" 82 target := "\"" + getTestPath("mta", "mtar_result") + "\"" 83 84 var stdout bytes.Buffer 85 cmd := exec.Command("bash", "-c", mbtCmdCLI+" build"+" --source "+source+" --target "+target) 86 cmd.Stdout = &stdout 87 88 Ω(cmd.Run()).Should(Succeed()) 89 Ω(os.RemoveAll(getTestPath("mta", "mtar_result"))).Should(Succeed()) 90 }) 91 It("Success - build with relative source and relative target path parameter", func() { 92 // Notice: target parameter is relative to source parameter 93 source := "\"" + "testdata/mta" + "\"" 94 target := "\"" + "mtar_result" + "\"" 95 96 var stdout bytes.Buffer 97 cmd := exec.Command("bash", "-c", mbtCmdCLI+" build"+" --source "+source+" --target "+target) 98 cmd.Stdout = &stdout 99 100 Ω(cmd.Run()).Should(Succeed()) 101 Ω(os.RemoveAll(getTestPath("mta", "mtar_result"))).Should(Succeed()) 102 }) 103 It("Failure - build with invalid source parameter case 1", func() { 104 // Notice: target parameter is relative to source parameter 105 source := "\"" + "testdata/**??mta" + "\"" 106 target := "\"" + "mtar_result" + "\"" 107 108 var stdout bytes.Buffer 109 cmd := exec.Command("bash", "-c", mbtCmdCLI+" build"+" --source "+source+" --target "+target) 110 cmd.Stdout = &stdout 111 112 Ω(cmd.Run()).Should(HaveOccurred()) 113 // Ω(stdout.String()).Should(ContainSubstring("The filename, directory name, or volume label syntax is incorrect")) 114 Ω(os.RemoveAll(getTestPath("mta", "mtar_result"))).Should(Succeed()) 115 }) 116 It("Failure - build with invalid source parameter case 2", func() { 117 // Notice: target parameter is relative to source parameter 118 source := "\"" + "testdata<></mta" + "\"" 119 target := "\"" + "mtar_result" + "\"" 120 121 var stdout bytes.Buffer 122 cmd := exec.Command("bash", "-c", mbtCmdCLI+" build"+" --source "+source+" --target "+target) 123 cmd.Stdout = &stdout 124 125 Ω(cmd.Run()).Should(HaveOccurred()) 126 // Ω(stdout.String()).Should(ContainSubstring("The filename, directory name, or volume label syntax is incorrect")) 127 Ω(os.RemoveAll(getTestPath("mta", "mtar_result"))).Should(Succeed()) 128 }) 129 /* It("Failure - build with invalid target parameter case 1", func() { 130 // Notice: target parameter is relative to source parameter 131 source := "\"" + "testdata/mta" + "\"" 132 target := "\"" + "mtar_result<>/tmp" + "\"" 133 var stdout bytes.Buffer 134 135 cmd := exec.Command("bash", "-c", mbtCmdCLI+" build"+" --source "+source+" --target "+target) 136 cmd.Stdout = &stdout 137 138 Ω(cmd.Run()).Should(HaveOccurred()) 139 //Ω(stdout.String()).Should(ContainSubstring("The filename, directory name, or volume label syntax is incorrect")) 140 Ω(os.RemoveAll(getTestPath("mta", "mtar_result"))).Should(Succeed()) 141 }) 142 It("Failure - build with invalid target parameter case 2", func() { 143 // Notice: target parameter is relative to source parameter 144 source := "\"" + "testdata/mta" + "\"" 145 target := "\"" + "mtar_result/??*tmp" + "\"" 146 var stdout bytes.Buffer 147 148 cmd := exec.Command("bash", "-c", mbtCmdCLI+" build"+" --source "+source+" --target "+target) 149 cmd.Stdout = &stdout 150 151 Ω(cmd.Run()).Should(HaveOccurred()) 152 //Ω(stdout.String()).Should(ContainSubstring("The filename, directory name, or volume label syntax is incorrect")) 153 Ω(os.RemoveAll(getTestPath("mta", "mtar_result"))).Should(Succeed()) 154 }) */ 155 It("Success - build with relative sbom-file-path parameter", func() { 156 source := "\"" + getTestPath("mta") + "\"" 157 sbom_file_path := "\"" + "sbom-gen-result/merged.bom.xml" + "\"" 158 159 cmd := exec.Command("bash", "-c", mbtCmdCLI+" build"+" --source "+source+" --sbom-file-path "+sbom_file_path) 160 161 Ω(cmd.Run()).Should(Succeed()) 162 Ω(os.RemoveAll(getTestPath("mta", dir.MtarFolder))).Should(Succeed()) 163 Ω(os.RemoveAll(getTestPath("mta", "sbom-gen-result"))).Should(Succeed()) 164 }) 165 It("Success - build with abs sbom-file-path parameter", func() { 166 source := "\"" + getTestPath("mta") + "\"" 167 sbom_file_path := "\"" + getTestPath("mta", "sbom-gen-result", "merged.bom.xml") + "\"" 168 169 cmd := exec.Command("bash", "-c", mbtCmdCLI+" build"+" --source "+source+" --sbom-file-path "+sbom_file_path) 170 171 Ω(cmd.Run()).Should(Succeed()) 172 Ω(os.RemoveAll(getTestPath("mta", dir.MtarFolder))).Should(Succeed()) 173 Ω(os.RemoveAll(getTestPath("mta", "sbom-gen-result"))).Should(Succeed()) 174 }) 175 It("Failure - build without mta.yaml", func() { 176 source := "\"" + getTestPath("tmp") + "\"" 177 Ω(os.MkdirAll(getTestPath("tmp"), os.ModePerm)).Should(Succeed()) 178 179 var stdout bytes.Buffer 180 cmd := exec.Command("bash", "-c", mbtCmdCLI+" build"+" --source "+source) 181 cmd.Stdout = &stdout 182 183 Ω(cmd.Run()).Should(HaveOccurred()) 184 Ω(os.RemoveAll(getTestPath("tmp"))).Should(Succeed()) 185 }) 186 It("Failure - build with invalid platform parameter", func() { 187 platform := "\"" + "xxx" + "\"" 188 source := "\"" + getTestPath("mta") + "\"" 189 190 var stdout bytes.Buffer 191 cmd := exec.Command("bash", "-c", mbtCmdCLI+" build"+" --source "+source+" --platform "+platform) 192 cmd.Stdout = &stdout 193 194 Ω(cmd.Run()).Should(HaveOccurred()) 195 }) 196 })