Integration Tests
Package for defining integration tests. Currently, there is a setup for API and Orchestrator testing.
Run locally
- Setup env variables in the root folder
infra/.env file
- If you made changes to the
api or envd protobuf spec, run make generate from this folder (and don't forget to generate it in envd if changes apply there too).
- If necessary, run
make connect-orchestrator to create a tunnel to one orchestrator client VM in GCP (you may need to run make setup-ssh the first time)
- Run
make test in this folder or make test-integration from the root infra/ folder.
Narrow the run with make test/<path under internal/tests>, e.g. make test/api/templates
or make test/api/templates/build_template_test.go:TestTemplateBuildCOPY.
What CI runs
The uncompressed config runs the whole suite. The compressed configs (zstd1,
lz4) re-run only scripts/compression-tests.tsv, the explicit allow-list of
tests whose subject is writing or reading back a snapshot; that file documents
the inclusion criteria and the code paths the compression knobs reach. Select it
locally with TESTS_ONLY=scripts/compression-tests.tsv make test. An entry that
no longer matches a real test is an error, so the list cannot rot into silently
reduced coverage.
Usage of clients (api, orchestrator, envd)
All tests are in the folder internal/tests. You can see the usage of different clients in the tests. Here are just basics.
API
HTTP client. In order to pass the API key, use the setup.WithAPIKey() option.
client := setup.GetAPIClient()
sbxTimeout := int32(60)
resp, err := client.PostSandboxesWithResponse(ctx, api.NewSandbox{
Timeout: &sbxTimeout,
}, setup.WithAPIKey())
Orchestrator
GRPC client. There is no authentication needed as it runs behind API in production.
client := setup.GetOrchestratorClient(t, ctx)
resp, err := client.List(ctx, &emptypb.Empty{})
Envd
Envd client is used for interacting with the sandbox.
There are two API types—HTTP and GRPC.
Each of them provides different methods for interacting with the sandbox; you need to check which ones you need.
HTTP
In order to access correct sandbox URL, you need to pass setup.WithSandbox(...) with the required arguments.
client := setup.GetEnvdClient(t, ctx)
resp, err := client.HTTPClient.PostFilesWithBodyWithResponse(
ctx,
...,
setup.WithSandbox(sbx.JSON201.SandboxID),
)
GRPC
In order to access correct sandbox URL, you need to call setup.SetSandboxHeader(...) with the required arguments.
All methods also expect a user (user/root) to be set in the header.
You can achieve it using setup.SetUserHeader(...).
client := setup.GetEnvdClient(t, ctx)
req := connect.NewRequest(&filesystem.ListDirRequest{
Path: "/",
})
setup.SetSandboxHeader(req.Header(), sbx.JSON201.SandboxID)
setup.SetUserHeader(req.Header(), "user")
resp, err := client.FilesystemClient.ListDir(ctx, req)