A small project that collects various nice things to get started with Go Web Development.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-web-starter-kit/tests/base_test.go

44 lines
1015 B

package tests
import (
"testing"
// "github.com/stretchr/testify/require"
"MY/webapp/data"
sq "github.com/Masterminds/squirrel"
)
func deleteTestUser(username string) {
sql, args, err := sq.Delete("user").Where("username=?", username).ToSql()
data.Exec(err, sql, args...)
}
func TestLogin(t *testing.T) {
deleteTestUser("testerzed")
z, cancel := Setup(t, 5)
defer cancel()
z.GoTo("/register/", `[data-testid="register-index-page"]`)
z.TypeIn(`#username`, `testerzed`)
z.TypeIn(`#email`, `zed@test.com`)
z.TypeIn(`#password`, `iamdumbass`)
z.ClickOn(`#register-submit`)
z.WaitFor(`[data-testid="login-index-page"]`)
z.GoTo("/login/", `[data-testid="login-index-page"]`)
z.TypeIn(`#username`, `testerzed`)
z.TypeIn(`#password`, `iamdumbass`)
z.ClickOn(`#login-submit`)
z.WaitFor(`[data-testid="index-page"]`)
/// delete the user here
deleteTestUser("testerzed")
}
func TestMain(m *testing.M) {
data.Setup("sqlite3", "./db.sqlite3")
m.Run()
data.Shutdown()
}