top

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()
}

Imported by 3 package(s)

  1. github.com/mendersoftware/deployments/utils/testing
  2. github.com/mendersoftware/go-lib-micro/testing
  3. github.com/mendersoftware/inventory/utils

Imported only in test by 126 package(s)

  1. bitbucket.org/hothai/trunkery
  2. github.com/8090boy/go-json-rest/rest
  3. github.com/AnuchitPrasertsang/contact-1
  4. github.com/DimShadoWWW/capturer
  5. github.com/ErebusBat/go-json-rest-middleware-jwt
  6. github.com/FraBle/simple-todo-list
  7. github.com/JekaMas/go-json-rest/rest
  8. github.com/KtorZ/go-json-rest/rest
  9. github.com/MaikuMori/go-json-rest/rest
  10. github.com/Pallat/api/handler
  11. github.com/Pallat/go_sim
  12. github.com/Pallat/reach
  13. github.com/STNS/STNS/stns
  14. github.com/SocialHarvestVendors/go-json-rest/rest
  15. github.com/Spokepoint/smtp-callback-verification
  16. github.com/StephanDollberg/go-json-rest-middleware-jwt
  17. github.com/Tovkal/go-json-rest/rest
  18. github.com/WnP/go-json-rest-middleware-jwt
  19. github.com/agrison/go-json-rest/rest
  20. github.com/aiyi/go-json-rest/rest
  21. github.com/alkasir/alkasir/pkg/shared/jwtmw
  22. github.com/angryfoxsu/Api.Go
  23. github.com/ant0ine/go-json-rest/rest
  24. github.com/benalexau/ibconnect.go/server
  25. github.com/benalexau/ibconnect/server
  26. github.com/bfallik/go-json-rest/rest
  27. github.com/canthefason/todo/todo
  28. github.com/chanshik/go-json-rest/rest
  29. github.com/clyphub/go-json-rest-middleware/redirect
  30. github.com/clyphub/go-json-rest/rest
  31. github.com/crunchydata/dnsbridge/deps/go-json-rest/rest
  32. github.com/cyberroadie/go-json-rest/rest
  33. github.com/dafang/go-json-rest/rest
  34. github.com/darvik80/go-json-rest/rest
  35. github.com/eAndrius/go-json-rest/rest
  36. github.com/eicca/smart-translate-server/api
  37. github.com/ghigt/go-json-rest-middleware-jwt
  38. github.com/gmaisto/go-json-rest/rest
  39. github.com/gwynantj/go-json-rest/rest
  40. github.com/hardPass/go-json-rest/rest
  41. github.com/huuzkee-foundation/go-json-rest/rest
  42. github.com/ikawaha/go-json-rest/rest
  43. github.com/iporsut/contact
  44. github.com/jadengore/go-json-rest-middleware-force-ssl
  45. github.com/jadengore/go-json-rest-middleware/redirect
  46. github.com/jadengore/go-json-rest/rest
  47. github.com/jburet/go-json-rest/rest
  48. github.com/jjenkins/go-json-rest/rest
  49. github.com/josharian/go-json-rest/rest
  50. github.com/joshheinrichs/geosource/server/api
  51. github.com/kimxilxyong/go-json-rest-middleware-jwt
  52. github.com/kristinn/go-json-rest/rest
  53. github.com/liangchenye/go-json-rest/rest
  54. github.com/lth2015/go-json-rest/rest
  55. github.com/maciejmrowiec/deviceauth
  56. github.com/maciejmrowiec/deviceauth/requestid
  57. github.com/maciejmrowiec/deviceauth/requestlog
  58. github.com/marconi/boltapi
  59. github.com/masahide/pyramid-scheme
  60. github.com/mattsch/go-json-rest/rest
  61. github.com/mclarkson/go-json-rest/rest
  62. github.com/mclarkson/obdi/external/ant0ine/go-json-rest/rest
  63. github.com/mendersoftware/deployments/resources/deployments/controller
  64. github.com/mendersoftware/deployments/resources/deployments/view
  65. github.com/mendersoftware/deployments/resources/images/controller
  66. github.com/mendersoftware/deployments/resources/images/view
  67. github.com/mendersoftware/deployments/utils/restutil
  68. github.com/mendersoftware/deviceauth/requestid
  69. github.com/mendersoftware/deviceauth/requestlog
  70. github.com/mendersoftware/go-lib-micro/requestid
  71. github.com/mendersoftware/go-lib-micro/requestlog
  72. github.com/mendersoftware/go-lib-micro/routing
  73. github.com/mendersoftware/inventory
  74. github.com/mendersoftware/inventory/requestid
  75. github.com/mendersoftware/inventory/requestlog
  76. github.com/mhemmings/go-json-rest/rest
  77. github.com/miha-stopar/go-json-rest/rest
  78. github.com/msutter/go-json-rest/rest
  79. github.com/novalagung/go-json-rest-middleware-jwt
  80. github.com/novalagung/go-json-rest/rest
  81. github.com/pallat/api/handler
  82. github.com/pallat/go_sim
  83. github.com/pallat/reach
  84. github.com/pdxjohnny/go-json-rest-middleware-jwt
  85. github.com/pdxjohnny/hangouts-call-center/http/api
  86. github.com/pdxjohnny/numapp/user/api
  87. github.com/peergum/go-json-rest/rest
  88. github.com/philboltt/postit
  89. github.com/pyama86/STNS/stns
  90. github.com/pyama86/go-json-rest/rest
  91. github.com/q2/go-json-rest/rest
  92. github.com/qapi/go-json-rest/rest
  93. github.com/qmsk/close/control
  94. github.com/radioinmyhead/go-rest
  95. github.com/robstrong/go-json-rest/rest
  96. github.com/roofimon/contact_2nd_try
  97. github.com/roofimon/contact_3rd_try
  98. github.com/roofimon/reach
  99. github.com/sebest/go-json-rest/rest
  100. github.com/sioncheng/go-json-rest/rest
  101. github.com/songshusen/go-json-rest/rest
  102. github.com/stephandollberg/go-json-rest-middleware-jwt
  103. github.com/theclapp/go-json-rest/rest
  104. github.com/tomjowitt/go-json-rest/rest
  105. github.com/ulule/limiter
  106. github.com/unravelin/go-json-rest/rest
  107. github.com/urakozz/go-json-rest-middleware-jwt
  108. github.com/valorbreak/go-json-rest/rest
  109. github.com/veqryn/go-json-rest/rest
  110. github.com/wallarelvo/backfire/backfire
  111. github.com/widnyana/go-json-rest/rest
  112. github.com/wingyplus/diameter_spike/omr_diameter
  113. github.com/wingyplus/go-json-rest/rest
  114. github.com/wppurking/limiter
  115. github.com/wuyingsong/go-json-rest/rest
  116. github.com/yangmls/vcron/rest
  117. github.com/yannk/go-json-rest/rest
  118. github.com/yetis-br/travelPlanning
  119. github.com/youngtrips/go-json-rest/rest
  120. github.com/zaybiz/go-json-rest/rest
  121. github.com/zupa-hu/go-json-rest/rest
  122. github.com/zx9597446/go-json-rest/rest
  123. github.com/zx9597446/sigchecker
  124. github.com/zx9597446/smstoken
  125. gopkg.in/ant0ine/go-json-rest.v2/rest
  126. gopkg.in/ant0ine/go-json-rest.v3/rest