Skip to content

Commit

Permalink
build: refactor oci-test
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Kotzbauer <git@ckotzbauer.de>
  • Loading branch information
ckotzbauer committed Dec 24, 2022
1 parent 7820629 commit f2ae41c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,7 @@ jobs:
install-cosign: true
install-syft: true
build-commands: make build
test-commands: |
DATE="$(date +%Y%m%d%H%M%S)"
docker build --build-arg date=${DATE} -t ttl.sh/sbom-operator-oci-test-${DATE}:1h internal/target/oci/fixtures
docker push ttl.sh/sbom-operator-oci-test-${DATE}:1h
DIGEST=$(docker inspect ttl.sh/sbom-operator-oci-test-${DATE}:1h --format='{{index .RepoDigests 0}}')
syft registry:${DIGEST} -o json > internal/target/oci/fixtures/sbom.json
TEST_DIGEST="${DIGEST}" go test $(go list ./...) -coverprofile cover.out
COSIGN_REPOSITORY="ttl.sh/sbom-operator-oci-test-${DATE}" cosign download sbom ${DIGEST}
test-commands: make test
report-coverage: true
coverage-file: cover.out
build-image: true
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ vet:
go vet ./...

test:
go test $(shell go list ./... | grep -v sbom-operator/internal/target/oci) -coverprofile cover.out
bash hack/run-tests.sh

lint:
$(LINTCMD)
Expand Down
10 changes: 10 additions & 0 deletions hack/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

DATE="$(date +%Y%m%d%H%M%S)"
docker build --build-arg date=${DATE} -t ttl.sh/sbom-operator-oci-test-${DATE}:1h internal/target/oci/fixtures
docker push ttl.sh/sbom-operator-oci-test-${DATE}:1h
DIGEST=$(docker inspect ttl.sh/sbom-operator-oci-test-${DATE}:1h --format='{{index .RepoDigests 0}}')
syft registry:${DIGEST} -o json > internal/target/oci/fixtures/sbom.json

TEST_DIGEST="${DIGEST}" DATE="${DATE}" go test $(go list ./...) -coverprofile cover.out
COSIGN_REPOSITORY="ttl.sh/sbom-operator-oci-test-${DATE}" cosign download sbom ${DIGEST}
3 changes: 2 additions & 1 deletion internal/target/oci/oci_target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (

func TestOci(t *testing.T) {
fmt.Printf("Image: %s", os.Getenv("TEST_DIGEST"))
oci := NewOciTarget("ghcr.io/ckotzbauer/sbom-operator/oci-test", os.Getenv("REGISTRY_USER"), os.Getenv("REGISTRY_TOKEN"), "json")
fmt.Printf("Date: %s", os.Getenv("DATE"))
oci := NewOciTarget(fmt.Sprintf("ttl.sh/sbom-operator-oci-test-%s", os.Getenv("DATE")), "", "", "json")
sbom, err := os.ReadFile("./fixtures/sbom.json")
assert.NoError(t, err)

Expand Down

0 comments on commit f2ae41c

Please sign in to comment.