diff --git a/tests/main.go b/tests/main.go new file mode 100644 index 0000000..50973b0 --- /dev/null +++ b/tests/main.go @@ -0,0 +1,19 @@ +package test + +import ( + _ "multitenantStack/routers" + + "github.com/astaxie/beego" + "github.com/astaxie/beego/orm" + _ "github.com/lib/pq" +) + +func init() { + orm.RegisterDataBase("default", "postgres", "host=127.0.0.1 port=5435 user=postgres password=postgre sslmode=disable") + orm.RegisterDataBase("company1", "postgres", "host=127.0.0.1 port=5435 user=postgres password=postgre dbname=company1 sslmode=disable") + orm.RegisterDataBase("company2", "postgres", "host=127.0.0.1 port=5435 user=postgres password=postgre dbname=company2 sslmode=disable") + + orm.Debug = true + beego.BConfig.WebConfig.DirectoryIndex = true + beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger" +} diff --git a/tests/main_test.go b/tests/main_test.go new file mode 100644 index 0000000..e40895f --- /dev/null +++ b/tests/main_test.go @@ -0,0 +1,41 @@ +package test + +import ( + "fmt" + "net/http" + "net/http/httptest" + "path/filepath" + "runtime" + "testing" + "time" + + "github.com/astaxie/beego" + . "github.com/smartystreets/goconvey/convey" +) + +func init() { + _, file, _, _ := runtime.Caller(0) + apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".."+string(filepath.Separator)))) + + beego.TestBeegoInit(apppath) + fmt.Println(apppath) +} + +// TestBeego is a sample to run an endpoint test +func TestBeego(t *testing.T) { + time.Sleep(1000) + r, _ := http.NewRequest("GET", "/v1/posts", nil) + w := httptest.NewRecorder() + + beego.BeeApp.Handlers.ServeHTTP(w, r) + beego.Trace("testing", "TestBeego", "Code [ %d ]\n%s", w.Code, w.Body.String()) + + Convey("Subject: Test Station Endpoint\n", t, func() { + Convey("Status Code Should Be 200", func() { + So(w.Code, ShouldEqual, 200) + }) + Convey("The Result Should Not Be Empty", func() { + So(w.Body.Len(), ShouldBeGreaterThan, 0) + }) + }) +}