我有以下测试文件:
package tests
import (
"net/http"
"net/http/httptest"
"testing"
"runtime"
"path/filepath"
_ "hello/routers"
_ "github.com/lib/pq"
"github.com/astaxie/beego"
. "github.com/smartystreets/goconvey/convey"
)
func init() {
_, file, _, _ := runtime.Caller(1)
apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".." + string(filepath.Separator))))
beego.TestBeegoInit(apppath)
}
// TestGet is a sample to run an endpoint test
func TestGet(t *testing.T) {
r, _ := http.NewRequest("GET", "/api/testing", nil)
w := httptest.NewRecorder()
beego.BeeApp.Handlers.ServeHTTP(w, r)
beego.Trace("testing", "TestGet", "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)
})
})
}
然后当我跑go test tests/*.go
我得到:
2015/01/14 23:55:19 [config.go:284] [W] open /home/IdeaProjects/go/src/hello/tests/conf/app.conf: no such file or directory
[ORM]register db Ping `default`, pq: password authentication failed for user "hello"
must have one register DataBase alias named `default`
FAIL command-line-arguments 0.008s
bee api
我已经使用 pq Postgres Driver for PG 数据库引导了 Beego 。
另外我不确定它为什么要查找它应该查找的文件/hello/tests/conf/app.conf
路径。app.conf
/hello/conf/app.conf
发生这种情况有原因吗?