From 3a7b97c153fe86bebb9e9ff2276723aae2d086a1 Mon Sep 17 00:00:00 2001 From: Roger Ng Date: Thu, 5 Sep 2024 18:41:58 +0100 Subject: [PATCH] Support `file://` scheme in integration test (#218) * Support `file://` scheme in integration test * Fix missing pointer for `logReadBaseURL` --- .github/workflows/integration_test.yml | 2 +- cmd/conformance/posix/docker/compose.yaml | 6 +---- integration/integration_test.go | 33 ++++++++++++++++++----- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/.github/workflows/integration_test.yml b/.github/workflows/integration_test.yml index fbe79a5a..7876c908 100644 --- a/.github/workflows/integration_test.yml +++ b/.github/workflows/integration_test.yml @@ -29,7 +29,7 @@ jobs: - name: Start Docker services (tessera-conformance-posix) run: docker compose -f ./cmd/conformance/posix/docker/compose.yaml up --build --detach - name: Run integration test - run: go test -v -race ./integration/... --run_integration_test=true --log_url="http://localhost:2025" --write_log_url="http://localhost:2025" --log_public_key="example.com/log/testdata+33d7b496+AeHTu4Q3hEIMHNqc6fASMsq3rKNx280NI+oO5xCFkkSx" + run: go test -v -race ./integration/... --run_integration_test=true --log_url="file:///tmp/tessera-posix-log" --write_log_url="http://localhost:2025" --log_public_key="example.com/log/testdata+33d7b496+AeHTu4Q3hEIMHNqc6fASMsq3rKNx280NI+oO5xCFkkSx" - name: Stop Docker services (tessera-conformance-posix) if: ${{ always() }} run: docker compose -f ./cmd/conformance/posix/docker/compose.yaml down diff --git a/cmd/conformance/posix/docker/compose.yaml b/cmd/conformance/posix/docker/compose.yaml index e359939f..6f5335c4 100644 --- a/cmd/conformance/posix/docker/compose.yaml +++ b/cmd/conformance/posix/docker/compose.yaml @@ -18,9 +18,5 @@ services: "--v=2", ] volumes: - - tiles:/tmp/tessera-posix-log + - /tmp/tessera-posix-log:/tmp/tessera-posix-log restart: always - -volumes: - tiles: - name: "tiles" diff --git a/integration/integration_test.go b/integration/integration_test.go index 7a457a1a..ba9f4d60 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -50,6 +50,9 @@ var ( noteVerifier note.Verifier + logReadBaseURL *url.URL + logRead client.Fetcher + hc = &http.Client{ Transport: &http.Transport{ MaxIdleConns: 256, @@ -74,6 +77,20 @@ func TestMain(m *testing.M) { klog.Fatalf("Failed to create new verifier: %v", err) } + logReadBaseURL, err = url.Parse(*logURL) + if err != nil { + klog.Fatalf("failed to parse logURL: %v", err) + } + + switch logReadBaseURL.Scheme { + case "http", "https": + logRead = httpRead + case "file": + logRead = fileRead + default: + klog.Fatalf("unsupported url scheme: %s", logReadBaseURL.Scheme) + } + os.Exit(m.Run()) } @@ -84,7 +101,7 @@ func TestLiveLogIntegration(t *testing.T) { // Step 1 - Get checkpoint initial size for increment validation. var checkpointInitSize uint64 - checkpoint, _, _, err := client.FetchCheckpoint(ctx, httpRead, noteVerifier, noteVerifier.Name()) + checkpoint, _, _, err := client.FetchCheckpoint(ctx, logRead, noteVerifier, noteVerifier.Name()) if err != nil { t.Errorf("client.FetchCheckpoint: %v", err) } @@ -111,7 +128,7 @@ func TestLiveLogIntegration(t *testing.T) { t.Errorf("entryWriter.add: %v", err) } entryIndexMap.Store(i, index) - checkpoint, _, _, err := client.FetchCheckpoint(ctx, httpRead, noteVerifier, noteVerifier.Name()) + checkpoint, _, _, err := client.FetchCheckpoint(ctx, logRead, noteVerifier, noteVerifier.Name()) if err != nil { t.Errorf("client.FetchCheckpoint: %v", err) } @@ -129,7 +146,7 @@ func TestLiveLogIntegration(t *testing.T) { } // Step 3 - Validate checkpoint size increment. - checkpoint, _, _, err = client.FetchCheckpoint(ctx, httpRead, noteVerifier, noteVerifier.Name()) + checkpoint, _, _, err = client.FetchCheckpoint(ctx, logRead, noteVerifier, noteVerifier.Name()) if err != nil { t.Errorf("client.FetchCheckpoint: %v", err) } @@ -148,7 +165,7 @@ func TestLiveLogIntegration(t *testing.T) { index := v.(uint64) // Step 4.1 - Get entry bundles to read back what was written, check leaves are correct. - entryBundle, err := client.GetEntryBundle(ctx, httpRead, index/256, checkpoint.Size) + entryBundle, err := client.GetEntryBundle(ctx, logRead, index/256, checkpoint.Size) if err != nil { t.Errorf("client.GetEntryBundle: %v", err) } @@ -159,7 +176,7 @@ func TestLiveLogIntegration(t *testing.T) { } // Step 4.2 - Test inclusion proofs. - pb, err := client.NewProofBuilder(ctx, *checkpoint, httpRead) + pb, err := client.NewProofBuilder(ctx, *checkpoint, logRead) if err != nil { t.Errorf("client.NewProofBuilder: %v", err) } @@ -176,7 +193,7 @@ func TestLiveLogIntegration(t *testing.T) { }) // Step 5 - Test consistency proofs. - if err := client.CheckConsistency(ctx, httpRead, checkpoints); err != nil { + if err := client.CheckConsistency(ctx, logRead, checkpoints); err != nil { t.Errorf("log consistency checks failed: %v", err) } } @@ -216,6 +233,10 @@ func httpRead(ctx context.Context, path string) ([]byte, error) { return body, nil } +func fileRead(_ context.Context, path string) ([]byte, error) { + return os.ReadFile(logReadBaseURL.JoinPath(path).Path) +} + type entryWriter struct { addURL string }