Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default_test.go generated by bee fails to utilize beego/v2/core/logs #763

Closed
gnosthi opened this issue Feb 9, 2021 · 1 comment
Closed

Comments

@gnosthi
Copy link

gnosthi commented Feb 9, 2021

While this is only a minor bug and should be easy enough to fix, its worth pointing out that the tests/default_test.go file that is generated by bee does not utilize the 2.0 logging mechanism but the old logging mechanism. It will therefore fail when doing go test ./tests/.

The offending code is:

import (
[...]
beego "github.com/beego/beego/v2/server/web"
[...]
)

[...]
func TestBeego(t *testing.T) {
 [...]
beego.Trace("testing", "TestBeego", "Code[%d]\n%s", w.Code, w.Body.String())
[...]
}

This should include the new logging mechanism like so.

package test

import (
	"net/http"
	"net/http/httptest"
	"testing"
	"runtime"
	"path/filepath"
	_ "openaltar-webapp/routers"

	beego "github.com/beego/beego/v2/server/web"
	. "github.com/smartystreets/goconvey/convey"
	log "github.com/beego/beego/v2/core/logs"
)

func init() {
	_, file, _, _ := runtime.Caller(0)
	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)
	w := httptest.NewRecorder()
	beego.BeeApp.Handlers.ServeHTTP(w, r)

	log.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)
	        })
	})
}

While I get that this file is not likely to be used as is, it might still be worth resolving for the sake of feature demonstration completeness.

@flycash
Copy link
Collaborator

flycash commented Feb 10, 2021

PR #756
Please check it.

@flycash flycash closed this as completed Mar 4, 2021
Baihhh pushed a commit to Baihhh/bee that referenced this issue Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants