From 1d0f13d727392f6c6aa82cf5c9ee8a9da66ec79e Mon Sep 17 00:00:00 2001 From: Justin McCarthy Date: Tue, 12 Mar 2024 15:11:22 -0700 Subject: [PATCH] integration_tests: automate corpus tests --- .github/workflows/corpus.yml | 25 +++++++++++++++++++++++++ integration_tests/.gitignore | 1 + integration_tests/corpus_test.go | 20 ++++++++++---------- 3 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/corpus.yml create mode 100644 integration_tests/.gitignore diff --git a/.github/workflows/corpus.yml b/.github/workflows/corpus.yml new file mode 100644 index 00000000..7c3f259e --- /dev/null +++ b/.github/workflows/corpus.yml @@ -0,0 +1,25 @@ +name: Nightly Test Corpus +on: + schedule: + - cron: "0 0 * * *" + push: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.22" + + - name: Download + run: curl -L -o integration_tests/corpus-tests.tar.gz https://raw.githubusercontent.com/cedar-policy/cedar-integration-tests/main/corpus-tests.tar.gz + + - name: Extract + run: mkdir -p integration_tests/tmp && tar -xzf integration_tests/corpus-tests.tar.gz -C integration_tests/tmp + + - name: Corpus Tests + run: go test -tags corpus ./integration_tests/... diff --git a/integration_tests/.gitignore b/integration_tests/.gitignore new file mode 100644 index 00000000..a9a5aecf --- /dev/null +++ b/integration_tests/.gitignore @@ -0,0 +1 @@ +tmp diff --git a/integration_tests/corpus_test.go b/integration_tests/corpus_test.go index b7602707..4a024f2f 100644 --- a/integration_tests/corpus_test.go +++ b/integration_tests/corpus_test.go @@ -1,3 +1,5 @@ +//go:build corpus + package integration_tests import ( @@ -12,13 +14,7 @@ import ( "golang.org/x/exp/slices" ) -// TODO: a way to download the corpus tests and test them -// for now, since this folder is 235MB. -// -// Remove the x before the next line if you have the corpus locally. -// And remove t.Skip() from the test itself. -// -// x go:embed tmp/* +//go:embed tmp/**/*.json tmp/**/*.cedar var integrationFS embed.FS type corpusTest struct { @@ -40,11 +36,9 @@ type corpusTest struct { func TestCorpus(t *testing.T) { t.Parallel() - t.Skip() var tests []string for _, p := range []string{ - "tmp/abac-B/*.json", - "tmp/abac-type-directed-B/*.json", + "tmp/corpus-tests/*.json", } { more, err := fs.Glob(integrationFS, p) if err != nil || len(more) == 0 { @@ -79,6 +73,12 @@ func TestCorpus(t *testing.T) { prefix := func(v string) string { return "tmp/" + v } + + // detect possible corpus data pipeline failure + if len(tests) < 4_000 { + t.Fatalf("corpus test count too low: %v", len(tests)) + } + for _, tn := range tests { tn := tn t.Run(tn, func(t *testing.T) {