From 3bde9ce5bddba1e9ee7d9de60ace091e591fba2d Mon Sep 17 00:00:00 2001 From: Roger Ng Date: Thu, 5 Sep 2024 16:28:00 +0000 Subject: [PATCH] Support `file://` scheme in integration test --- .github/workflows/integration_test.yml | 2 +- cmd/conformance/posix/docker/compose.yaml | 6 +--- integration/integration_test.go | 35 +++++++++++++++++++---- 3 files changed, 31 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..903a68b1 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -50,6 +50,8 @@ var ( noteVerifier note.Verifier + logRead client.Fetcher + hc = &http.Client{ Transport: &http.Transport{ MaxIdleConns: 256, @@ -74,6 +76,20 @@ func TestMain(m *testing.M) { klog.Fatalf("Failed to create new verifier: %v", err) } + logURL, err := url.Parse(*logURL) + if err != nil { + klog.Fatalf("failed to parse logURL: %v", err) + } + + switch logURL.Scheme { + case "http", "https": + logRead = httpRead + case "file": + logRead = fileRead + default: + klog.Fatalf("unsupported url scheme: %s", logURL.Scheme) + } + os.Exit(m.Run()) } @@ -84,7 +100,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 +127,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 +145,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 +164,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 +175,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 +192,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 +232,13 @@ func httpRead(ctx context.Context, path string) ([]byte, error) { return body, nil } +func fileRead(_ context.Context, path string) ([]byte, error) { + logURL, _ := url.Parse(*logURL) + logURL = logURL.JoinPath(path) + + return os.ReadFile(logURL.Path) +} + type entryWriter struct { addURL string }