Skip to content

Commit

Permalink
Support file:// scheme in integration test (#218)
Browse files Browse the repository at this point in the history
* Support `file://` scheme in integration test

* Fix missing pointer for `logReadBaseURL`
  • Loading branch information
roger2hk authored Sep 5, 2024
1 parent da2d50f commit 3a7b97c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 1 addition & 5 deletions cmd/conformance/posix/docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
33 changes: 27 additions & 6 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ var (

noteVerifier note.Verifier

logReadBaseURL *url.URL
logRead client.Fetcher

hc = &http.Client{
Transport: &http.Transport{
MaxIdleConns: 256,
Expand All @@ -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())
}

Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 3a7b97c

Please sign in to comment.