Micro & pluggable web framework for Go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
703B

  1. package tango
  2. import (
  3. "bytes"
  4. "fmt"
  5. "net/http"
  6. "net/http/httptest"
  7. "testing"
  8. )
  9. func TestGroupGroup(t *testing.T) {
  10. var a int
  11. tg := Classic()
  12. tg.Group("/api", func(api *Group) {
  13. api.Group("/v1", func(v1 *Group) {
  14. v1.Use(HandlerFunc(func(ctx *Context) {
  15. a = 1
  16. ctx.Next()
  17. }))
  18. v1.Get("/", func(ctx *Context) {
  19. fmt.Println("context")
  20. })
  21. })
  22. })
  23. buff := bytes.NewBufferString("")
  24. recorder := httptest.NewRecorder()
  25. recorder.Body = buff
  26. req, err := http.NewRequest("GET", "http://localhost:8000/api/v1", nil)
  27. if err != nil {
  28. t.Error(err)
  29. }
  30. tg.ServeHTTP(recorder, req)
  31. expect(t, recorder.Code, http.StatusOK)
  32. expect(t, buff.String(), "")
  33. expect(t, 1, a)
  34. }