File: doc.go

package info (click to toggle)
golang-github-ant0ine-go-json-rest 3.3.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 324 kB
  • sloc: makefile: 2
file content (33 lines) | stat: -rw-r--r-- 1,308 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Utility functions to help writing tests for a Go-Json-Rest app
//
// Go comes with net/http/httptest to help writing test for an http
// server. When this http server implements a JSON REST API, some basic
// checks end up to be always the same. This test package tries to save
// some typing by providing helpers for this particular use case.
//
//      package main
//
//      import (
//              "github.com/ant0ine/go-json-rest/rest"
//              "github.com/ant0ine/go-json-rest/rest/test"
//              "testing"
//      )
//
//      func TestSimpleRequest(t *testing.T) {
//              api := rest.NewApi()
//              api.Use(rest.DefaultDevStack...)
//              router, err := rest.MakeRouter(
//                      rest.Get("/r", func(w rest.ResponseWriter, r *rest.Request) {
//                              w.WriteJson(map[string]string{"Id": "123"})
//                      }),
//              )
//              if err != nil {
//                     log.Fatal(err)
//              }
//              api.SetApp(router)
//              recorded := test.RunRequest(t, api.MakeHandler(),
//                      test.MakeSimpleRequest("GET", "http://1.2.3.4/r", nil))
//              recorded.CodeIs(200)
//              recorded.ContentTypeIsJson()
//      }
package test