> ## Documentation Index
> Fetch the complete documentation index at: https://docs.varianz.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Go

> Test with the varianztest package: sessions with automatic cleanup, CEL stages, and fluent sample assertions in standard go test.

The Go test integration is the `varianztest` package in the SDK module — no separate install:

```go theme={null}
import (
    "testing"
    "time"

    vt "go.varianz.io/sdk/varianztest"
)

func TestPriceOverride(t *testing.T) {
    session := vt.NewSession(t, "http://localhost:50051")

    session.Insert(vt.Cel("pricing/calculate-price", "42"))
    session.AwaitSyncOrFail(5 * time.Second)

    // Trigger with the session header
    resp := callService(t, "/price", body,
        map[string]string{"x-varianz-id": session.SessionID()})

    assert.Equal(t, 42.0, resp["total"])
}
```

`vt.NewSession(t, endpoint)` registers cleanup with `t` — stages are removed and the session destroyed when the test ends. Run `go test` with the [standard environment](/reference/configuration) (`VARIANZ_ENABLED=true`, and `VARIANZ_INSECURE_ALLOW_PLAINTEXT=true` for a plaintext local registry).

## Stage examples

```go theme={null}
vt.Cel("pricing/calculate-price", "42")                              // constant override
vt.Cel("pricing/calculate-price", "invoke() * 2")                    // transform the real result
vt.Cel("pricing/calculate-price", "args.base_price + args.quantity") // read inputs
vt.Cel("pricing/calculate-price", "ctx.applyTax(invoke(), 0.1)")     // context function
vt.Cel("pricing/calculate-price", `sample("result", invoke())`)      // probe
```

Field names in `args` follow the Go SDK's [field-naming rules](/sdks/go#field-names) — `BasePrice` is `args.base_price` unless tagged otherwise.

## Session API

| Method                       | Description                                                                                                               |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| `vt.NewSession(t, endpoint)` | Create a session with auto-cleanup                                                                                        |
| `SessionID()`                | 32-char hex session ID                                                                                                    |
| `Insert(stage)`              | Insert a stage (use `vt.Cel(target, expr)`)                                                                               |
| `AwaitSync(timeout)`         | Wait for subscriber confirmation, returns the result                                                                      |
| `AwaitSyncOrFail(timeout)`   | Wait; fail the test on timeout or validation failure; see [zero-subscriber semantics](/testing/overview#zero-subscribers) |
| `AssertSample(ident)`        | Start a fluent sample assertion                                                                                           |
| `Samples()`                  | The raw sample hub                                                                                                        |

## Sample assertions

```go theme={null}
session.AssertSample("result").
    Within(10 * time.Second).
    Exists().
    HasCount(1).
    HasValue("total", 100.0)
```

`HasValue` takes a dot path into the sampled value (`""` for the value itself); `Samples()` on the assertion returns the collected raw samples when you need custom checks.

## In-process calls

When the code under test is in the same process, put the session on the context instead of a header:

```go theme={null}
ctx := varianz.WithSession(context.Background(), session.SessionID())
got, err := CalculatePrice(ctx, req)
```
