Can now run ChromeDP to automate the browser based testing.
This commit is contained in:
parent
81aaffec56
commit
b28e507e5e
6 changed files with 72 additions and 7 deletions
5
Makefile
5
Makefile
|
@ -10,5 +10,8 @@ docs:
|
|||
build_docs:
|
||||
go tool godoc -v -http=localhost:6060 -index -index_files godoc.idx -write_index
|
||||
|
||||
test:
|
||||
go test
|
||||
|
||||
dev:
|
||||
go tool air
|
||||
go tool air -build.stop_on_error "true"
|
||||
|
|
37
chromedp_test.go
Normal file
37
chromedp_test.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package webapp
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"context"
|
||||
"time"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/chromedp/chromedp"
|
||||
)
|
||||
|
||||
func TestHelloName(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
assert.Equal(123, 123, "should be equal")
|
||||
assert.NotEqual(123, 456, "should not be equal")
|
||||
}
|
||||
|
||||
func TestChromeDPWorks(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
ctx, cancel := chromedp.NewContext(context.Background())
|
||||
defer cancel()
|
||||
|
||||
ctx, cancel = context.WithTimeout(ctx, 15 * time.Second)
|
||||
defer cancel()
|
||||
|
||||
var example string
|
||||
|
||||
err := chromedp.Run(ctx,
|
||||
chromedp.Navigate(`http://127.0.0.1:5002`),
|
||||
chromedp.WaitVisible(`body > footer`),
|
||||
chromedp.Click(`#example`, chromedp.NodeVisible),
|
||||
chromedp.Value(`#example textarea`, &example),
|
||||
)
|
||||
|
||||
assert.NoError(err)
|
||||
}
|
10
go.mod
10
go.mod
|
@ -9,6 +9,7 @@ require (
|
|||
github.com/gofiber/template/html/v2 v2.1.3
|
||||
github.com/jmoiron/sqlx v1.4.0
|
||||
github.com/mattn/go-sqlite3 v1.14.28
|
||||
github.com/stretchr/testify v1.10.0
|
||||
)
|
||||
|
||||
require (
|
||||
|
@ -24,9 +25,13 @@ require (
|
|||
github.com/bep/godartsass/v2 v2.5.0 // indirect
|
||||
github.com/bep/golibsass v1.2.0 // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||
github.com/chromedp/cdproto v0.0.0-20250611220608-a17eb1ae8ff0 // indirect
|
||||
github.com/chromedp/chromedp v0.13.6 // indirect
|
||||
github.com/chromedp/sysutil v1.1.0 // indirect
|
||||
github.com/cli/browser v1.3.0 // indirect
|
||||
github.com/coder/websocket v1.8.13 // indirect
|
||||
github.com/creack/pty v1.1.24 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/elastic/go-sysinfo v1.15.3 // indirect
|
||||
github.com/elastic/go-windows v1.0.2 // indirect
|
||||
|
@ -35,10 +40,14 @@ require (
|
|||
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
|
||||
github.com/go-faster/city v1.0.1 // indirect
|
||||
github.com/go-faster/errors v0.7.1 // indirect
|
||||
github.com/go-json-experiment/json v0.0.0-20250517221953-25912455fbc8 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-sql-driver/mysql v1.9.2 // indirect
|
||||
github.com/gobwas/glob v0.2.3 // indirect
|
||||
github.com/gobwas/httphead v0.1.0 // indirect
|
||||
github.com/gobwas/pool v0.2.1 // indirect
|
||||
github.com/gobwas/ws v1.4.0 // indirect
|
||||
github.com/gofiber/template v1.8.3 // indirect
|
||||
github.com/gofiber/utils v1.1.0 // indirect
|
||||
github.com/gohugoio/hugo v0.147.6 // indirect
|
||||
|
@ -68,6 +77,7 @@ require (
|
|||
github.com/pelletier/go-toml v1.9.5 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||
github.com/pierrec/lz4/v4 v4.1.22 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/pressly/goose/v3 v3.24.3 // indirect
|
||||
github.com/prometheus/procfs v0.16.1 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
|
|
14
go.sum
14
go.sum
|
@ -72,6 +72,12 @@ github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA
|
|||
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/chromedp/cdproto v0.0.0-20250611220608-a17eb1ae8ff0 h1:tXxiImKSoSzfGjFxxNU0A1/idO0tbbNsPHNomsBlRd4=
|
||||
github.com/chromedp/cdproto v0.0.0-20250611220608-a17eb1ae8ff0/go.mod h1:NItd7aLkcfOA/dcMXvl8p1u+lQqioRMq/SqDp71Pb/k=
|
||||
github.com/chromedp/chromedp v0.13.6 h1:xlNunMyzS5bu3r/QKrb3fzX6ow3WBQ6oao+J65PGZxk=
|
||||
github.com/chromedp/chromedp v0.13.6/go.mod h1:h8GPP6ZtLMLsU8zFbTcb7ZDGCvCy8j/vRoFmRltQx9A=
|
||||
github.com/chromedp/sysutil v1.1.0 h1:PUFNv5EcprjqXZD9nJb9b/c9ibAbxiYo4exNWZyipwM=
|
||||
github.com/chromedp/sysutil v1.1.0/go.mod h1:WiThHUdltqCNKGc4gaU50XgYjwjYIhKWoHGPTUfWTJ8=
|
||||
github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME=
|
||||
github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
|
||||
github.com/cli/browser v1.3.0 h1:LejqCrpWr+1pRqmEPDGnTZOjsMe7sehifLynZJuqJpo=
|
||||
|
@ -127,6 +133,8 @@ github.com/go-faster/city v1.0.1 h1:4WAxSZ3V2Ws4QRDrscLEDcibJY8uf41H6AhXDrNDcGw=
|
|||
github.com/go-faster/city v1.0.1/go.mod h1:jKcUJId49qdW3L1qKHH/3wPeUstCVpVSXTM6vO3VcTw=
|
||||
github.com/go-faster/errors v0.7.1 h1:MkJTnDoEdi9pDabt1dpWf7AA8/BaSYZqibYyhZ20AYg=
|
||||
github.com/go-faster/errors v0.7.1/go.mod h1:5ySTjWFiphBs07IKuiL69nxdfd5+fzh1u7FPGZP2quo=
|
||||
github.com/go-json-experiment/json v0.0.0-20250517221953-25912455fbc8 h1:o8UqXPI6SVwQt04RGsqKp3qqmbOfTNMqDrWsc4O47kk=
|
||||
github.com/go-json-experiment/json v0.0.0-20250517221953-25912455fbc8/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M=
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
|
@ -150,6 +158,12 @@ github.com/gobuffalo/flect v1.0.3 h1:xeWBM2nui+qnVvNM4S3foBhCAL2XgPU+a7FdpelbTq4
|
|||
github.com/gobuffalo/flect v1.0.3/go.mod h1:A5msMlrHtLqh9umBSnvabjsMrCcCpAyzglnDvkbYKHs=
|
||||
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
|
||||
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
|
||||
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
|
||||
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
|
||||
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
|
||||
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
|
||||
github.com/gobwas/ws v1.4.0 h1:CTaoG1tojrh4ucGPcoJFiAQUAsEWekEWvLy7GsVNqGs=
|
||||
github.com/gobwas/ws v1.4.0/go.mod h1:G3gNqMNtPppf5XUz7O4shetPpcZ1VJ7zt18dlUeakrc=
|
||||
github.com/gofiber/fiber/v2 v2.52.8 h1:xl4jJQ0BV5EJTA2aWiKw/VddRpHrKeZLF0QPUxqn0x4=
|
||||
github.com/gofiber/fiber/v2 v2.52.8/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw=
|
||||
github.com/gofiber/template v1.8.3 h1:hzHdvMwMo/T2kouz2pPCA0zGiLCeMnoGsQZBTSYgZxc=
|
||||
|
|
8
main.go
8
main.go
|
@ -11,10 +11,7 @@ import (
|
|||
"github.com/jmoiron/sqlx"
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/gofiber/fiber/v2/middleware/recover"
|
||||
"github.com/gofiber/fiber/v2/middleware/encryptcookie"
|
||||
"github.com/gofiber/fiber/v2/middleware/session"
|
||||
"github.com/gofiber/fiber/v2/middleware/helmet"
|
||||
"github.com/gofiber/fiber/v2/middleware/basicauth"
|
||||
)
|
||||
|
||||
type Link struct {
|
||||
|
@ -50,6 +47,9 @@ func main() {
|
|||
|
||||
// handler that returns one json from a sql database
|
||||
app.Get("/api/stream/", func (c *fiber.Ctx) error {
|
||||
sess, err := store.Get(c)
|
||||
sess.Set("fuck", "off")
|
||||
|
||||
sql, args, err := sq.Select("*").From("stream").ToSql()
|
||||
return tools.SelectJson[Stream](db, c, err, sql, args...)
|
||||
})
|
||||
|
@ -78,7 +78,7 @@ func main() {
|
|||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
c.Redirect("/live/")
|
||||
return c.Redirect("/live/")
|
||||
} else {
|
||||
return c.Redirect("/live/")
|
||||
}
|
||||
|
|
|
@ -58,11 +58,12 @@ func ReceivePost[T any](c *fiber.Ctx) (*T, error) {
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func Insert(db *sqlx.DB, err error, sql string, args ...interface{}) error {
|
||||
func Insert(db *sqlx.DB, err error, sql_query string, args ...interface{}) error {
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return db.MustExec(sql, args...)
|
||||
_, exec_err := db.NamedExec(sql_query, args)
|
||||
return exec_err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue