Fix- e2e tests to include the executable

Included e2e tests for the executable with JSON
This commit is contained in:
naveen 2021-02-12 16:54:06 -05:00 committed by Naveen
parent 30d69310c6
commit af2132e927
4 changed files with 90 additions and 6 deletions

View File

@ -21,18 +21,20 @@ jobs:
run: make test
- name: Build
run: make build
- name: Run e2e
- name: Run ci-e2e
env:
GITHUB_AUTH_TOKEN: ${{ secrets.GH_AUTH_TOKEN }}
run: |
if [[ ! -v GITHUB_AUTH_TOKEN ]]; then
echo "GITHUB_AUTH_TOKEN is not set, skip test"
exit 1
elif [[ -z "$GITHUB_AUTH_TOKEN" ]]; then
echo "GITHUB_AUTH_TOKEN is set to the empty string, skip test"
exit 1
else
go get github.com/onsi/ginkgo/ginkgo@v1.14.2
go mod download
make e2e
make ci-e2e
fi
- uses: codecov/codecov-action@v1
with:

3
.gitignore vendored
View File

@ -10,9 +10,10 @@ scorecard
# Test binary, built with `go test -c`.
*.test
results.json
# Output of the go coverage tool, specifically when used with LiteIDE.
*.coverprofile
*.coverprofile*
# IDE directories.

View File

@ -1,4 +1,5 @@
all: fmt tidy lint test
SHELL := /bin/bash
all: fmt tidy lint test
build:
go build
@ -22,8 +23,22 @@ golangci-lint:
lint: golangci-lint ## Run golangci-lint linter
$(GOLANGCI_LINT) run
check-env:
ifndef GITHUB_AUTH_TOKEN
$(error GITHUB_AUTH_TOKEN is undefined)
endif
.PHONY: e2e
# export GITHUB_AUTH_TOKEN with personal access token to run the e2e
e2e:
ginkgo -v -cover ./...
e2e: build check-env
ginkgo --skip="E2E TEST:executable" -p -v -cover ./...
.PHONY: ci-e2e
# export GITHUB_AUTH_TOKEN with personal access token to run the e2e
ci-e2e: build check-env
$(call ndef, GITHUB_AUTH_TOKEN)
mkdir -p bin
./scorecard --repo=https://github.com/ossf/scorecard --format json > ./bin/results.json
ginkgo -p -v -cover ./...

66
e2e/executable_test.go Normal file
View File

@ -0,0 +1,66 @@
package e2e
import (
"encoding/json"
"io/ioutil"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
type scorecard struct {
Repo string `json:"Repo"`
Date string `json:"Date"`
Checks []struct {
CheckName string `json:"CheckName"`
Pass bool `json:"Pass"`
Confidence int `json:"Confidence"`
Details []string `json:"Details"`
} `json:"Checks"`
}
var _ = Describe("E2E TEST:executable", func() {
Context("E2E TEST:Validating executable test", func() {
It("Should return valid test results for scorecard", func() {
file, _ := ioutil.ReadFile("../bin/results.json")
data := scorecard{}
err := json.Unmarshal([]byte(file), &data)
Expect(err).Should(BeNil())
for _, c := range data.Checks {
switch c.CheckName {
case "Active":
Expect(c.Pass).Should(BeTrue(), c.CheckName)
case "Branch-Protection":
Expect(c.Pass).Should(BeTrue(), c.CheckName)
case "CI-Tests":
Expect(c.Pass).Should(BeTrue(), c.CheckName)
case "CII-Best-Practices":
Expect(c.Pass).Should(BeFalse(), c.CheckName)
case "Code-Review":
Expect(c.Pass).Should(BeTrue(), c.CheckName)
case "Contributors":
Expect(c.Pass).Should(BeTrue(), c.CheckName)
case "Frozen-Deps":
Expect(c.Pass).Should(BeTrue(), c.CheckName)
case "Fuzzing":
Expect(c.Pass).Should(BeFalse(), c.CheckName)
case "Packaging":
Expect(c.Pass).Should(BeTrue(), c.CheckName)
case "Pull-Requests":
Expect(c.Pass).Should(BeTrue(), c.CheckName)
case "SAST":
Expect(c.Pass).Should(BeTrue(), c.CheckName)
case "Signed-Releases":
Expect(c.Pass).Should(BeFalse(), c.CheckName)
case "Signed-Tags":
Expect(c.Pass).Should(BeFalse(), c.CheckName)
}
}
})
})
})