iris-httptest

command
v14.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

A tasks API tested in main_test.go with the framework's own github.com/kataras/iris/v14/httptest package.

The sibling ../std-httptest directory holds the SAME application with tests written against net/http/httptest and encoding/json only. Read the two test files side by side to pick the style you prefer.

What makes this application testable is the newApp(cfg, repo) seam: it takes its configuration and its storage as arguments and returns an application that has not started listening. main passes production values, a test passes its own, and both drive the same router, middleware and error map.

Learn: test an Iris application without opening a port, assert on JSON, headers and cookies, and swap storage for a fake through the newApp seam.

Run:

go test -v
ADMIN_PASSWORD=change-me go run main.go

Try:

curl -i -X POST localhost:8080/api/tasks -d '{"title":"buy milk"}'   # 201 {"id":"..."}
curl localhost:8080/api/tasks                                        # 200, the task list
curl -i localhost:8080/api/admin/stats                               # 401, no credentials
curl -u admin:change-me localhost:8080/api/admin/stats               # 200 {"open":1,"admin":"admin"}

Next: ../std-httptest

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL