Skip to content

Commit 8599d45

Browse files
kvapsclaude
andcommitted
test(contract): BLOCKSTOR_BASEURL switches smoke replay to deployed target
When set, smoke harness skips the in-process server and replays against the URL — used by stand integration to hit the live controller via port-forward instead of an ephemeral one. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
1 parent b2cd5d7 commit 8599d45

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

tests/contract/smoke_test.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package contract_test
1919
import (
2020
"context"
2121
"net"
22+
"os"
2223
"strings"
2324
"testing"
2425
"time"
@@ -38,7 +39,7 @@ import (
3839
// here to pin blockstor's own contract. Cross-impl trace recording is
3940
// future operational work.
4041
func TestSmokeTraceReplay(t *testing.T) {
41-
addr, stop := startServer(t)
42+
baseURL, stop := resolveTarget(t)
4243
defer stop()
4344

4445
traces, err := contract.LoadTracesDir("testdata/smoke")
@@ -50,7 +51,7 @@ func TestSmokeTraceReplay(t *testing.T) {
5051
t.Fatalf("no smoke traces found")
5152
}
5253

53-
results, err := contract.Replay(t.Context(), nil, "http://"+addr, traces)
54+
results, err := contract.Replay(t.Context(), nil, baseURL, traces)
5455
if err != nil {
5556
t.Fatalf("Replay: %v", err)
5657
}
@@ -62,6 +63,22 @@ func TestSmokeTraceReplay(t *testing.T) {
6263
}
6364
}
6465

66+
// resolveTarget returns a base URL to replay against. If
67+
// BLOCKSTOR_BASEURL is set in the env (e.g. CI hits a deployed
68+
// controller via port-forward), use it as-is and skip the in-process
69+
// server. Otherwise boot one and tear it down via the returned func.
70+
func resolveTarget(t *testing.T) (string, func()) {
71+
t.Helper()
72+
73+
if url := os.Getenv("BLOCKSTOR_BASEURL"); url != "" {
74+
return url, func() {}
75+
}
76+
77+
addr, stop := startServer(t)
78+
79+
return "http://" + addr, stop
80+
}
81+
6582
// startServer boots an in-process blockstor REST server on a random
6683
// loopback port. It picks a port by listening + closing (the small
6784
// race window is acceptable for tests), starts the server, then waits

0 commit comments

Comments
 (0)