Skip to content

Commit

Permalink
fix validation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
patilpankaj212 committed Feb 18, 2021
1 parent 456cb31 commit cce5a7b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 12 deletions.
1 change: 1 addition & 0 deletions scripts/generate-coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/e2e/init/golden/init_help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
3 changes: 3 additions & 0 deletions test/e2e/init/ignore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package init

// This file is added to ignore 'no non-test Go files' issue
4 changes: 2 additions & 2 deletions test/e2e/init/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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() {
Expand Down
18 changes: 9 additions & 9 deletions test/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
13 changes: 13 additions & 0 deletions tools/tools.go
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit cce5a7b

Please sign in to comment.