default_test.go 956 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package test
  2. import (
  3. "net/http"
  4. "net/http/httptest"
  5. "testing"
  6. "runtime"
  7. "path/filepath"
  8. _ "PPGo_ApiAdmin/routers"
  9. "github.com/astaxie/beego"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. func init() {
  13. _, file, _, _ := runtime.Caller(1)
  14. apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".." + string(filepath.Separator))))
  15. beego.TestBeegoInit(apppath)
  16. }
  17. // TestBeego is a sample to run an endpoint test
  18. func TestBeego(t *testing.T) {
  19. r, _ := http.NewRequest("GET", "/", nil)
  20. w := httptest.NewRecorder()
  21. beego.BeeApp.Handlers.ServeHTTP(w, r)
  22. beego.Trace("testing", "TestBeego", "Code[%d]\n%s", w.Code, w.Body.String())
  23. Convey("Subject: Test Station Endpoint\n", t, func() {
  24. Convey("Status Code Should Be 200", func() {
  25. So(w.Code, ShouldEqual, 200)
  26. })
  27. Convey("The Result Should Not Be Empty", func() {
  28. So(w.Body.Len(), ShouldBeGreaterThan, 0)
  29. })
  30. })
  31. }