Feat - e2e tests for gitcache buckets

Implemented e2e tests for buckets.
This commit is contained in:
naveen 2021-03-05 03:54:47 +00:00 committed by Naveen
parent 90d3fa7e70
commit 018043f4cf
3 changed files with 35 additions and 6 deletions

View File

@ -23,10 +23,20 @@ all: build
.PHONY: build
build: ## Runs go build and generates executable
CGO_ENABLED=0 go build -a -tags netgo -ldflags '-w -extldflags "-static"' -o gitblobcache
CGO_ENABLED=0 go build -a -ldflags '-w -extldflags "-static"' -o gitblobcache
.phony: dockerbuild
dockerbuild: ## runs docker build
$(call ndef, github_auth_token)
docker build . --tag $(IMAGE_NAME)
check-env:
ifndef BLOB_URL
$(error BLOB_URL is undefined)
endif
.PHONY: ci-e2e
ci-e2e: build check-env ## runs ci-e2e tests
$(call ndef, BLOB_URL)
ginkgo -v -cover ./e2e/...

View File

@ -14,13 +14,33 @@
package e2e
import (
"os"
. "github.com/onsi/ginkgo"
_ "github.com/onsi/gomega"
. "github.com/onsi/gomega"
"github.com/ossf/scorecard/gitcache/pkg"
)
var _ = Describe("E2E TEST:gitcache", func() {
Context("E2E TEST:Validating gitcache", func() {
var _ = Describe("E2E TEST:bucket cache", func() {
Context("E2E TEST:Validating bucket cache", func() {
var cache *pkg.Cache
var err error
It("Should be able to connect to the blob store", func() {
bucketURI := os.Getenv("BLOB_URL")
Expect(len(bucketURI)).ShouldNot(BeZero())
cache, err = pkg.NewBucket(bucketURI)
Expect(err).Should(BeNil())
Expect(cache).ShouldNot(BeNil())
})
It("should be able to add content to the bucket", func() {
const key string = "E2E_TEST_BUCKET"
//nolint
cache.Delete(key) // ignoring if the delete throws an error key not found
Expect(cache.Set(key, []byte(key))).Should(BeNil())
s, b := cache.Get(key)
Expect(b).Should(BeTrue())
Expect(string(s)).Should(BeEquivalentTo(key))
Expect(cache.Delete(key)).Should(BeNil())
})
})
})

View File

@ -45,8 +45,7 @@ func (c *Cache) Set(key string, resp []byte) error {
return c.Bucket.WriteAll(context.Background(), key, resp, nil)
}
// Delete removes key from the cache.The error is not returned to maintain compatibility
// with the httpcache Cache interface.
// Delete removes key from the cache.
func (c *Cache) Delete(key string) error {
return c.Bucket.Delete(context.Background(), key)
}