Skip to content

Commit

Permalink
Support file:// scheme in integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
roger2hk committed Sep 5, 2024
1 parent ffef2bb commit 3bde9ce
Show file tree
Hide file tree
Showing 3 changed files with 31 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"
35 changes: 29 additions & 6 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ var (

noteVerifier note.Verifier

logRead client.Fetcher

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

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

0 comments on commit 3bde9ce

Please sign in to comment.