This commit is contained in:
pengtao 2020-09-28 16:57:36 +08:00
parent 0a0a60da6c
commit 2a3a1aa776
5 changed files with 19 additions and 18 deletions

View File

@ -1,3 +1,3 @@
appname = devops
appname = go_ops
httpport = 8080
runmode = dev

6
go.mod
View File

@ -3,4 +3,8 @@ module go_ops
go 1.15
require github.com/astaxie/beego v1.12.1
require github.com/smartystreets/goconvey v1.6.4
require (
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect
github.com/smartystreets/goconvey v1.6.4
)

View File

@ -1,11 +1,10 @@
package main
import (
_ "devops/routers"
"github.com/astaxie/beego"
_ "go_ops/routers"
)
func main() {
beego.Run()
}

View File

@ -1,10 +1,10 @@
package routers
import (
"devops/controllers"
"github.com/astaxie/beego"
"go_ops/controllers"
)
func init() {
beego.Router("/", &controllers.MainController{})
beego.Router("/", &controllers.MainController{})
}

View File

@ -1,12 +1,12 @@
package test
import (
_ "go_ops/routers"
"net/http"
"net/http/httptest"
"testing"
"runtime"
"path/filepath"
_ "devops/routers"
"runtime"
"testing"
"github.com/astaxie/beego"
. "github.com/smartystreets/goconvey/convey"
@ -14,11 +14,10 @@ import (
func init() {
_, file, _, _ := runtime.Caller(0)
apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".." + string(filepath.Separator))))
apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".."+string(filepath.Separator))))
beego.TestBeegoInit(apppath)
}
// TestBeego is a sample to run an endpoint test
func TestBeego(t *testing.T) {
r, _ := http.NewRequest("GET", "/", nil)
@ -28,12 +27,11 @@ func TestBeego(t *testing.T) {
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)
})
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)
})
})
}