mirror of
https://github.com/ossf/scorecard.git
synced 2024-09-11 08:55:27 +03:00
feat - Included tests for disk cache
Included tests for disk cache. Cleaned up tests.
This commit is contained in:
parent
c2ff48dc59
commit
7b192a0243
15
.github/workflows/integration.yml
vendored
15
.github/workflows/integration.yml
vendored
@ -63,15 +63,16 @@ jobs:
|
||||
run: |
|
||||
go get github.com/onsi/ginkgo/ginkgo@v1.14.2
|
||||
go mod download
|
||||
mkdir -p $OUTPUT_PATH
|
||||
|
||||
- name: Run E2E with Disk Cache
|
||||
- name: Run E2E
|
||||
env:
|
||||
GITHUB_AUTH_TOKEN: ${{ secrets.GH_AUTH_TOKEN }}
|
||||
run: |
|
||||
go get github.com/onsi/ginkgo/ginkgo@v1.14.2
|
||||
make ci-e2e
|
||||
sleep 1m # this required to avoid 403 from GitHub API's
|
||||
run: make ci-e2e
|
||||
|
||||
- name: Test disk cache
|
||||
env:
|
||||
GITHUB_AUTH_TOKEN: ${{ secrets.GH_AUTH_TOKEN }}
|
||||
run: make test-disk-cache
|
||||
|
||||
- name: Test Blob cache
|
||||
env:
|
||||
@ -80,7 +81,7 @@ jobs:
|
||||
BLOB_URL: ${{secrets.BUCKET_URL}}
|
||||
run: |
|
||||
./scorecard --repo=https://github.com/ossf/scorecard --show-details --metadata=openssf --format json > ./$OUTPUT_PATH/results.json
|
||||
ginkgo --focus="E2E TEST:executable|E2E TEST:blob" ./...
|
||||
ginkgo --focus="E2E TEST:executable|E2E TEST:blob" ./e2e/...
|
||||
|
||||
- name: Build docker image
|
||||
run: docker build . --file Dockerfile --tag $IMAGE_NAME
|
||||
|
35
Makefile
35
Makefile
@ -3,7 +3,8 @@ GOBIN ?= $(GOPATH)/bin
|
||||
GINKGO ?= $(GOBIN)/ginkgo
|
||||
IMAGE_NAME = scorecard
|
||||
OUTPUT = output
|
||||
|
||||
FOCUS_DISK_TEST="E2E TEST:Disk Cache|E2E TEST:executable"
|
||||
IGNORED_CI_TEST="E2E TEST:blob|E2E TEST:Disk Cache|E2E TEST:executable"
|
||||
.PHONY: help
|
||||
help: ## Display this help
|
||||
@awk \
|
||||
@ -57,16 +58,37 @@ e2e: build check-env ginkgo
|
||||
ginkgo:
|
||||
GO111MODULE=off go get -u github.com/onsi/ginkgo/ginkgo
|
||||
|
||||
unexport USE_DISK_CACHE
|
||||
unexport USE_BLOB_CACHE
|
||||
ci-e2e: ## Runs ci e2e tests
|
||||
.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 $(OUTPUT)
|
||||
mkdir -p cache
|
||||
USE_DISK_CACHE=1 DISK_CACHE_PATH="./cache" ./scorecard --repo=https://github.com/ossf/scorecard --show-details --metadata=openssf --format json > ./$(OUTPUT)/results.json
|
||||
@sleep 30
|
||||
ginkgo -p -v -cover --skip="E2E TEST:blob" ./...
|
||||
@echo Ignoring these test for ci-e2e $(IGNORED_CI_TEST)
|
||||
ginkgo -p -v -cover --skip=$(IGNORED_CI_TEST) ./e2e/...
|
||||
|
||||
.PHONY: test-disk-cache
|
||||
test-disk-cache: build ## Runs disk cache tests
|
||||
$(call ndef, GITHUB_AUTH_TOKEN)
|
||||
# Start with clean cache
|
||||
rm -rf $(OUTPUT)
|
||||
rm -rf cache
|
||||
mkdir $(OUTPUT)
|
||||
mkdir cache
|
||||
@echo Focusing on these tests $(FOCUS_DISK_TEST)
|
||||
USE_DISK_CACHE=1 DISK_CACHE_PATH="./cache" \
|
||||
./scorecard \
|
||||
--repo=https://github.com/ossf/scorecard \
|
||||
--show-details --metadata=openssf --format json > ./$(OUTPUT)/results.json
|
||||
USE_DISK_CACHE=1 DISK_CACHE_PATH="./cache" ginkgo -p -v -cover --focus=$(FOCUS_DISK_TEST) ./e2e/...
|
||||
# Rerun the same test with the disk cache filled to make sure the cache is working.
|
||||
USE_DISK_CACHE=1 DISK_CACHE_PATH="./cache" \
|
||||
./scorecard \
|
||||
--repo=https://github.com/ossf/scorecard --show-details \
|
||||
--metadata=openssf --format json > ./$(OUTPUT)/results.json
|
||||
USE_DISK_CACHE=1 DISK_CACHE_PATH="./cache" ginkgo -p -v -cover --focus=$(FOCUS_DISK_TEST) ./e2e/...
|
||||
|
||||
|
||||
|
||||
# Verification targets
|
||||
@ -84,3 +106,4 @@ verify-go-mod: ## Verify the go modules
|
||||
dockerbuild: ## Runs docker build
|
||||
$(call ndef, GITHUB_AUTH_TOKEN)
|
||||
docker build . --file Dockerfile --tag $(IMAGE_NAME)
|
||||
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
|
||||
var _ = Describe("E2E TEST:Branch Protection", func() {
|
||||
Context("E2E TEST:Validating branch protection", func() {
|
||||
It("Should fail to return branch protection on other respositories", func() {
|
||||
It("Should fail to return branch protection on other repositories", func() {
|
||||
l := log{}
|
||||
checker := checker.Checker{
|
||||
Ctx: context.Background(),
|
||||
|
29
e2e/diskcache_test.go
Normal file
29
e2e/diskcache_test.go
Normal file
@ -0,0 +1,29 @@
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("E2E TEST:Disk Cache", func() {
|
||||
Context("E2E TEST:Disk cache is caching the request", func() {
|
||||
It("Should cache requests to the disk", func() {
|
||||
const (
|
||||
UseDiskCache = "USE_DISK_CACHE"
|
||||
DiskCachePath = "DISK_CACHE_PATH"
|
||||
)
|
||||
Expect(len(os.Getenv(UseDiskCache))).ShouldNot(BeZero())
|
||||
Expect(len(os.Getenv(DiskCachePath))).ShouldNot(BeZero())
|
||||
|
||||
// Validating if the files have been cached.
|
||||
files, err := ioutil.ReadDir(path.Join("../", os.Getenv(DiskCachePath)))
|
||||
|
||||
Expect(err).Should(BeNil())
|
||||
Expect(len(files)).Should(BeNumerically(">", 1), "Number of files should be greater than 1")
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user