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

yaptest demo: use TestServer to test #40

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ytest/classfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (p *App) TestServer(host string, app yap.AppType) {
app.InitYap()
app.SetLAS(func(addr string, h http.Handler) error {
svr := httptest.NewServer(h)
p.Host(host, svr.URL)
p.Host("http://"+host, svr.URL)
return nil
})
app.(interface{ MainEntry() }).MainEntry()
Expand All @@ -78,7 +78,7 @@ func (p *App) RunMock(host string, h http.Handler) {
// RunTestServer runs a HTTP server by httptest.Server.
func (p *App) RunTestServer(host string, h http.Handler) {
svr := httptest.NewServer(h)
p.Host(host, svr.URL)
p.Host("http://"+host, svr.URL)
}

// Gopt_App_TestMain is required by Go+ compiler as the TestMain entry of a YAP testing project.
Expand Down
10 changes: 10 additions & 0 deletions ytest/demo/foo/bar_ytest.gox
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
testServer "foo.com", new(foo)

run "get /p/$id", => {
id := "123"
get "http://foo.com/p/${id}"
ret 200
json {
"id": "12",
}
}
22 changes: 22 additions & 0 deletions ytest/demo/foo/gop_autogen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,28 @@ import (
"testing"
)

type case_bar struct {
ytest.Case
}
type case_foo struct {
ytest.Case
}
//line ytest/demo/foo/bar_ytest.gox:1
func (this *case_bar) Main() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[staticcheck] receiver name should be a reflection of its identity; don't use generic names such as "this" or "self" (ST1006)

//line ytest/demo/foo/bar_ytest.gox:1:1
this.TestServer("foo.com", new(foo))
//line ytest/demo/foo/bar_ytest.gox:3:1
this.Run("get /p/$id", func() {
//line ytest/demo/foo/bar_ytest.gox:4:1
id := "123"
//line ytest/demo/foo/bar_ytest.gox:5:1
this.Get("http://foo.com/p/" + id)
//line ytest/demo/foo/bar_ytest.gox:6:1
this.RetWith(200)
//line ytest/demo/foo/bar_ytest.gox:7:1
this.Json(map[string]string{"id": "12"})
})
}
//line ytest/demo/foo/foo_ytest.gox:1
func (this *case_foo) Main() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[staticcheck] receiver name should be a reflection of its identity; don't use generic names such as "this" or "self" (ST1006)

//line ytest/demo/foo/foo_ytest.gox:1:1
Expand All @@ -24,6 +43,9 @@ func (this *case_foo) Main() {
this.Json(map[string]string{"id": "12"})
})
}
func Test_bar(t *testing.T) {
ytest.Gopt_Case_TestMain(new(case_bar), t)
}
func Test_foo(t *testing.T) {
ytest.Gopt_Case_TestMain(new(case_foo), t)
}