default_test.go 952 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package test
  2. import (
  3. _ "Medical_ERP/routers"
  4. "net/http"
  5. "net/http/httptest"
  6. "path/filepath"
  7. "runtime"
  8. "testing"
  9. "github.com/beego/beego/v2/core/logs"
  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. // TestGet is a sample to run an endpoint test
  19. func TestGet(t *testing.T) {
  20. r, _ := http.NewRequest("GET", "/v1/object", nil)
  21. w := httptest.NewRecorder()
  22. beego.BeeApp.Handlers.ServeHTTP(w, r)
  23. logs.Info("testing", "TestGet", "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. }