-
Notifications
You must be signed in to change notification settings - Fork 24
/
main_test.go
52 lines (49 loc) · 1.57 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"github.com/GoAdminGroup/demo/tables"
"github.com/GoAdminGroup/go-admin/modules/config"
"github.com/GoAdminGroup/go-admin/tests"
"github.com/GoAdminGroup/go-admin/tests/common"
"github.com/GoAdminGroup/go-admin/tests/frameworks/gin"
"github.com/GoAdminGroup/go-admin/tests/web"
"github.com/gavv/httpexpect"
"net/http"
"testing"
)
// Black box testing
func TestDemoBlackBox(t *testing.T) {
tests.BlackBoxTestSuit(t, gin.NewHandler, config.DatabaseList{
"default": config.Database{
Host: "127.0.0.1",
Port: "3306",
User: "root",
Pwd: "root",
Name: "go_admin_demo_test", // WARNING: test database name must contains "test"
Driver: "mysql",
},
}, tables.Generators, func(cfg config.DatabaseList) {
// Data cleaner of the framework
tests.Cleaner(cfg)
// Clean your own data:
// ...
}, func(e *httpexpect.Expect) {
// Test cases of the framework
common.Test(e)
// Write your own API test, for example:
// More usages: https://github.com/gavv/httpexpect
e.POST("/signin").Expect().Status(http.StatusOK)
})
}
// User acceptance testing
func TestDemoUserAcceptance(t *testing.T) {
web.UserAcceptanceTestSuit(t, func(t *testing.T, page *web.Page) {
// Write test case base on chromedriver, for example:
// More usages: https://github.com/sclevine/agouti
page.NavigateTo("http://127.0.0.1:9033/admin")
page.Contain("username")
page.Click("")
}, func(quit chan struct{}) {
// start the server:
// ....
}, true) // if local parameter is true, it will not be headless, and window not close when finishing tests.
}