More coverage report setup.
This commit is contained in:
parent
831b5ea762
commit
23c6092aa6
3 changed files with 40 additions and 28 deletions
11
Makefile
11
Makefile
|
|
@ -16,3 +16,14 @@ test:
|
||||||
|
|
||||||
dev:
|
dev:
|
||||||
go tool air -build.stop_on_error "true"
|
go tool air -build.stop_on_error "true"
|
||||||
|
|
||||||
|
coverage:
|
||||||
|
go build -cover -o webapp
|
||||||
|
mkdir -p .coverage
|
||||||
|
echo "GOCOVERDIR=.coverage ./webapp"
|
||||||
|
|
||||||
|
cover_report:
|
||||||
|
go tool covdata textfmt -i=.coverage -o coverage.txt
|
||||||
|
go tool cover -func=coverage.txt
|
||||||
|
go tool cover -html=coverage.txt -o coverage.html
|
||||||
|
open coverage.html
|
||||||
|
|
|
||||||
55
main.go
55
main.go
|
|
@ -2,7 +2,11 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
"zedshaw.games/webapp/tools"
|
"zedshaw.games/webapp/tools"
|
||||||
|
"zedshaw.games/webapp/data"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/fiber/v2/middleware/logger"
|
"github.com/gofiber/fiber/v2/middleware/logger"
|
||||||
"github.com/gofiber/template/html/v2"
|
"github.com/gofiber/template/html/v2"
|
||||||
|
|
@ -10,29 +14,10 @@ import (
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
sq "github.com/Masterminds/squirrel"
|
sq "github.com/Masterminds/squirrel"
|
||||||
"github.com/gofiber/fiber/v2/middleware/recover"
|
recov "github.com/gofiber/fiber/v2/middleware/recover"
|
||||||
"github.com/gofiber/fiber/v2/middleware/session"
|
"github.com/gofiber/fiber/v2/middleware/session"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Login struct {
|
|
||||||
Username string `db:"username" validate:"required"`
|
|
||||||
Password string `db:"password" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Link struct {
|
|
||||||
Id int `db:"id" json:"id"`
|
|
||||||
StreamId int `db:"stream_id" json:"stream_id" form:"stream_id" validate:"required,numeric"`
|
|
||||||
Url string `db:"url" json:"url" form:"url" validate:"required,url"`
|
|
||||||
Description string `db:"description" json:"description" form:"description" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Stream struct {
|
|
||||||
Id int `db:"id" json:"id"`
|
|
||||||
Title string `db:"title" json:"title"`
|
|
||||||
Description string `db:"description" json:"description"`
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||||
|
|
||||||
|
|
@ -48,7 +33,7 @@ func main() {
|
||||||
Views: engine,
|
Views: engine,
|
||||||
})
|
})
|
||||||
app.Use(logger.New())
|
app.Use(logger.New())
|
||||||
app.Use(recover.New())
|
app.Use(recov.New())
|
||||||
|
|
||||||
// handler that returns one json from a sql database
|
// handler that returns one json from a sql database
|
||||||
app.Get("/api/stream/", func (c *fiber.Ctx) error {
|
app.Get("/api/stream/", func (c *fiber.Ctx) error {
|
||||||
|
|
@ -56,23 +41,23 @@ func main() {
|
||||||
sess.Set("fuck", "off")
|
sess.Set("fuck", "off")
|
||||||
|
|
||||||
sql, args, err := sq.Select("*").From("stream").ToSql()
|
sql, args, err := sq.Select("*").From("stream").ToSql()
|
||||||
return tools.SelectJson[Stream](db, c, err, sql, args...)
|
return tools.SelectJson[data.Stream](db, c, err, sql, args...)
|
||||||
})
|
})
|
||||||
|
|
||||||
app.Get("/api/stream/:id", func (c *fiber.Ctx) error {
|
app.Get("/api/stream/:id", func (c *fiber.Ctx) error {
|
||||||
sql, args, err := sq.Select("*").From("stream").Where("id", c.Params("id")).ToSql()
|
sql, args, err := sq.Select("*").From("stream").Where("id", c.Params("id")).ToSql()
|
||||||
return tools.GetJson[Stream](db, c, err, sql, args...)
|
return tools.GetJson[data.Stream](db, c, err, sql, args...)
|
||||||
})
|
})
|
||||||
|
|
||||||
app.Get("/api/stream/:id/links", func (c *fiber.Ctx) error {
|
app.Get("/api/stream/:id/links", func (c *fiber.Ctx) error {
|
||||||
sql, args, err := sq.Select("*").From("stream_link").Where("stream_id", c.Params("id")).ToSql()
|
sql, args, err := sq.Select("*").From("stream_link").Where("stream_id", c.Params("id")).ToSql()
|
||||||
|
|
||||||
return tools.SelectJson[Link](db, c, err, sql, args...)
|
return tools.SelectJson[data.Link](db, c, err, sql, args...)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
app.Post("/api/login", func (c *fiber.Ctx) error {
|
app.Post("/api/login", func (c *fiber.Ctx) error {
|
||||||
login, err := tools.ReceivePost[Login](c)
|
login, err := tools.ReceivePost[data.Login](c)
|
||||||
|
|
||||||
if(err != nil) {
|
if(err != nil) {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
|
@ -85,7 +70,7 @@ func main() {
|
||||||
})
|
})
|
||||||
|
|
||||||
app.Post("/api/link", func (c *fiber.Ctx) error {
|
app.Post("/api/link", func (c *fiber.Ctx) error {
|
||||||
link, err := tools.ReceivePost[Link](c)
|
link, err := tools.ReceivePost[data.Link](c)
|
||||||
if(err != nil) {
|
if(err != nil) {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
c.Redirect("/live/")
|
c.Redirect("/live/")
|
||||||
|
|
@ -111,5 +96,21 @@ func main() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Fatal(app.Listen(":5001"))
|
go func() {
|
||||||
|
if err := app.Listen(":5001"); err != nil {
|
||||||
|
log.Panic(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
c := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
|
||||||
|
_ = <-c
|
||||||
|
log.Println("Shutdown now...")
|
||||||
|
_ = app.Shutdown()
|
||||||
|
|
||||||
|
log.Println("Running cleanup...")
|
||||||
|
db.Close()
|
||||||
|
|
||||||
|
log.Println("Done.")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ func TestStreamPage(t *testing.T) {
|
||||||
var example string
|
var example string
|
||||||
|
|
||||||
Run(assert, ctx,
|
Run(assert, ctx,
|
||||||
browser.Navigate(`http://127.0.0.1:5002`),
|
browser.Navigate(`http://127.0.0.1:5001`),
|
||||||
browser.WaitVisible(`body > footer`),
|
browser.WaitVisible(`body > footer`),
|
||||||
browser.Click(`#streams`, browser.NodeVisible),
|
browser.Click(`#streams`, browser.NodeVisible),
|
||||||
browser.Text(`#streams-title`, &example))
|
browser.Text(`#streams-title`, &example))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue