default_test.go 955 B

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