Open-Source Wikis

/

Ollama

/

How to contribute

/

Testing

ollama/ollama

Testing

The test suite uses standard testing plus github.com/stretchr/testify for assertions. Tests live alongside the code they cover.

Layout

.
├── api/client_test.go               # client unit tests
├── cmd/cmd_test.go                  # CLI argument parsing and handlers
├── cmd/launch/<integration>_test.go # one per launch integration
├── server/
│   ├── routes_test.go               # generic server tests
│   ├── routes_generate_test.go      # /api/generate
│   ├── routes_create_test.go        # /api/create
│   ├── routes_cloud_test.go         # cloud passthrough
│   ├── routes_harmony_streaming_test.go
│   └── ...
├── middleware/anthropic_test.go     # OpenAI/Anthropic compat
├── middleware/openai_test.go
├── parser/parser_test.go
├── llm/server_test.go
├── runner/                          # runner-side tests
└── integration/                     # cross-process tests, build-tagged

Running tests

go test ./...                                  # everything that's not build-tagged
go test -race ./...                            # add the race detector
go test -run TestChatHandler ./server          # filter by name
go test -count=1 ./...                         # disable test cache
go test -tags=integration ./integration/...    # cross-process integration suite

Conventions

Table-driven goldens

The biggest test files (middleware/anthropic_test.go, cmd/launch/openclaw_test.go, server/routes_generate_test.go) are table-driven: a slice of structs each holding an input, expected output, and name. Sub-tests are run with t.Run(tt.name, ...). Use this pattern when adding new translation logic — see existing tests in the same package for the exact shape.

*testing.T helpers

Repeated setup is captured in private helpers: t.Helper() is called inside, and the helper either returns the constructed value or registers t.Cleanup for tear-down. See server/test_home_test.go for a typical home-directory override.

Capability checks before running

Some tests skip when the host can't satisfy them — e.g., GPU-required integration tests skip on CI runners without GPUs. Use t.Skip early.

Test data

Golden fixtures sit next to the tests in testdata/ directories (e.g., convert/testdata/, model/parsers/testdata/). Update them in the same commit as the code that produces them, and make sure the test prints diffs (most tests use cmp.Diff from github.com/google/go-cmp so failures are readable).

Stretching the scheduler

Scheduler tests in server/sched_test.go inject custom loadFn, newServerFn, getGpuFn, and getSystemInfoFn instead of touching real GPUs or subprocess starts. New scheduler behavior should follow the same hook pattern.

What to test

CONTRIBUTING.md gives the rule succinctly:

Strive to test behavior, not implementation.

In practice that means:

  • For HTTP changes, hit the handler with a real httptest.NewRecorder and assert on the response body.
  • For CLI changes, exercise the cobra command via cmd_test.go helpers; don't mock cobra itself.
  • For Modelfile changes, run parser.ParseFile on a string and inspect the resulting Modelfile.Commands and the request CreateRequest() produces.
  • For launch integrations, use the helpers in cmd/launch/test_config_helpers_test.go and golden-compare the rewritten config files.

Continuous integration

Workflows live under .github/workflows/:

File Purpose
test.yaml The main lint + test matrix that runs on every PR.
test-install.yaml Installer smoke tests.
release.yaml Cuts releases when a vX.Y.Z tag is pushed.
latest.yaml Promotes a release to "latest" once verified.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Testing – Ollama wiki | Factory