main_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package main
  2. import (
  3. "log"
  4. "testing"
  5. "github.com/GoAdminGroup/example/tables"
  6. "github.com/GoAdminGroup/go-admin/modules/config"
  7. "github.com/GoAdminGroup/go-admin/tests"
  8. "github.com/GoAdminGroup/go-admin/tests/common"
  9. "github.com/GoAdminGroup/go-admin/tests/frameworks/gin"
  10. "github.com/GoAdminGroup/go-admin/tests/web"
  11. "github.com/gavv/httpexpect"
  12. )
  13. // Black box testing
  14. func TestExampleBlackBox(t *testing.T) {
  15. tests.BlackBoxTestSuit(t, gin.NewHandler, config.DatabaseList{
  16. "default": config.Database{
  17. File: "./admin_test.db",
  18. Driver: "sqlite",
  19. },
  20. }, tables.Generators, func(cfg config.DatabaseList) {
  21. // Data cleaner of the framework
  22. tests.Cleaner(cfg)
  23. // Clean your own data:
  24. // ...
  25. }, func(e *httpexpect.Expect) {
  26. // Test cases of the framework
  27. common.Test(e)
  28. // Write your own API test, for example:
  29. // More usages: https://github.com/gavv/httpexpect
  30. // e.POST("/signin").Expect().Status(http.StatusOK)
  31. })
  32. }
  33. // User acceptance testing
  34. func TestExampleUserAcceptance(t *testing.T) {
  35. web.UserAcceptanceTestSuit(t, func(t *testing.T, page *web.Page) {
  36. // Write test case base on chromedriver, for example:
  37. // More usages: https://github.com/sclevine/agouti
  38. page.NavigateTo("http://127.0.0.1:9033/admin")
  39. //page.Contain("username")
  40. //page.Click("")
  41. }, func(quit chan struct{}) {
  42. // start the server:
  43. // ....
  44. go startServer()
  45. <-quit
  46. log.Print("test quit")
  47. }, true) // if local parameter is true, it will not be headless, and window not close when finishing tests.
  48. }