diff --git a/scripts/generate-coverage.sh b/scripts/generate-coverage.sh index 90978c878..2d0ffe140 100755 --- a/scripts/generate-coverage.sh +++ b/scripts/generate-coverage.sh @@ -4,5 +4,6 @@ set -o errexit set -o nounset set -o pipefail +export TERRASCAN_BIN_PATH=${PWD}/bin/terrascan go test -v -coverpkg=./... -coverprofile=coverage.out ./... go tool cover -func coverage.out diff --git a/test/e2e/init/golden/init_help.txt b/test/e2e/init/golden/init_help.txt index 2195be35f..0a2d2a485 100644 --- a/test/e2e/init/golden/init_help.txt +++ b/test/e2e/init/golden/init_help.txt @@ -12,4 +12,4 @@ Global Flags: -c, --config-path string config file path -l, --log-level string log level (debug, info, warn, error, panic, fatal) (default "info") -x, --log-type string log output type (console, json) (default "console") - -o, --output string output type (human, json, yaml, xml) (default "human") + -o, --output string output type (human, json, yaml, xml, junit-xml) (default "human") diff --git a/test/e2e/init/ignore.go b/test/e2e/init/ignore.go new file mode 100644 index 000000000..235dab9fb --- /dev/null +++ b/test/e2e/init/ignore.go @@ -0,0 +1,3 @@ +package init + +// This file is added to ignore 'no non-test Go files' issue diff --git a/test/e2e/init/init_test.go b/test/e2e/init/init_test.go index added5313..2f0245d17 100644 --- a/test/e2e/init/init_test.go +++ b/test/e2e/init/init_test.go @@ -46,7 +46,7 @@ var _ = Describe("Init", func() { }) Describe("terrascan init is run", func() { - When("terrascan init is run without any flags", func() { + When("without any flags", func() { It("should download policies and exit with status code 0", func() { session = helper.RunCommand(terrascanBinaryPath, outWriter, errWriter, "init") Eventually(session, initCommandTimeout).Should(gexec.Exit(0)) @@ -143,7 +143,7 @@ var _ = Describe("Init", func() { It("should error out and exit with status code 1", func() { session = helper.RunCommand(terrascanBinaryPath, outWriter, errWriter, "init") Eventually(session, initCommandTimeout).Should(gexec.Exit(1)) - helper.ContainsErrorSubString(session, `failed to checkout branch 'invalid-branch'. error: 'reference not found'`) + helper.ContainsErrorSubString(session, `failed to initialize terrascan. error : failed to checkout git branch 'invalid-branch'. error: 'reference not found'`) }) }) When("the config file has invalid rego subdir", func() { diff --git a/test/helper/helper.go b/test/helper/helper.go index 9eae13800..88b77c0ae 100644 --- a/test/helper/helper.go +++ b/test/helper/helper.go @@ -6,33 +6,33 @@ import ( "os" "os/exec" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" "github.com/onsi/gomega/gexec" ) // CompareActualWithGolden compares func CompareActualWithGolden(session *gexec.Session, goldenFileAbsPath string, isStdOut bool) { fileData, err := ioutil.ReadFile(goldenFileAbsPath) - Expect(err).NotTo(HaveOccurred()) + gomega.Expect(err).NotTo(gomega.HaveOccurred()) if isStdOut { - Expect(string(session.Wait().Out.Contents())).Should(BeIdenticalTo(string(fileData))) + gomega.Expect(string(session.Wait().Out.Contents())).Should(gomega.BeIdenticalTo(string(fileData))) } else { - Expect(string(session.Wait().Err.Contents())).Should(BeIdenticalTo(string(fileData))) + gomega.Expect(string(session.Wait().Err.Contents())).Should(gomega.BeIdenticalTo(string(fileData))) } } // ContainsErrorSubString will assert if error string is part of error output func ContainsErrorSubString(session *gexec.Session, errSubString string) { - Expect(string(session.Wait().Err.Contents())).Should(ContainSubstring(errSubString)) + gomega.Expect(string(session.Wait().Err.Contents())).Should(gomega.ContainSubstring(errSubString)) } // GetTerrascanBinaryPath returns the terrascan binary path func GetTerrascanBinaryPath() string { terrascanBinaryPath := os.Getenv("TERRASCAN_BIN_PATH") - Describe("terrascan binary path should be set for executing tests", func() { + ginkgo.Describe("terrascan binary path should be set for executing tests", func() { if terrascanBinaryPath == "" { - Fail("ensure that TERRASCAN_BIN_PATH is set") + ginkgo.Fail("ensure that TERRASCAN_BIN_PATH is set") } }) return terrascanBinaryPath @@ -42,6 +42,6 @@ func GetTerrascanBinaryPath() string { func RunCommand(path string, outWriter, errWriter io.Writer, args ...string) *gexec.Session { cmd := exec.Command(path, args...) session, err := gexec.Start(cmd, outWriter, errWriter) - Expect(err).NotTo(HaveOccurred()) + gomega.Expect(err).NotTo(gomega.HaveOccurred()) return session } diff --git a/tools/tools.go b/tools/tools.go new file mode 100644 index 000000000..8cf1325b6 --- /dev/null +++ b/tools/tools.go @@ -0,0 +1,13 @@ +// +build tools + +package tools + +import ( + // used only for testing + _ "github.com/onsi/ginkgo/ginkgo" + // used only for testing + _ "github.com/onsi/gomega" +) + +// This file imports packages that are used when running go generate, or used +// during the development process but not otherwise depended on by built code.