3

我有以下测试文件:

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

发生这种情况有原因吗?

4

1 回答 1

0

PG 无法对您进行身份验证可能是因为它在app.conf文件中找不到密码,它也找不到密码,因为它在错误的位置查找。

尝试使用配置的绝对路径,而不是init()函数中的复杂方法。

于 2015-01-14T13:11:49.883 回答