diff --git a/main.go b/main.go
index 921882a..75629de 100644
--- a/main.go
+++ b/main.go
@@ -14,6 +14,11 @@ import (
"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"`
@@ -65,6 +70,20 @@ func main() {
return tools.SelectJson[Link](db, c, err, sql, args...)
})
+
+ app.Post("/api/login", func (c *fiber.Ctx) error {
+ login, err := tools.ReceivePost[Login](c)
+
+ if(err != nil) {
+ log.Println(err)
+ c.Redirect("/error/")
+ }
+
+ log.Printf("username: %s; password: %s", login.Username, login.Password);
+
+ return c.Redirect("/")
+ })
+
app.Post("/api/link", func (c *fiber.Ctx) error {
link, err := tools.ReceivePost[Link](c)
if(err != nil) {
diff --git a/public/base.html b/public/base.html
new file mode 100644
index 0000000..db8b9e6
--- /dev/null
+++ b/public/base.html
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+ ZedShaw's Game Thing
+
+
+
+
+
+ 🏡 Zed's Game Dev Website Yay
+
+
+
+
+
+
+
+
+
diff --git a/public/error/index.html b/public/error/index.html
new file mode 100644
index 0000000..f828bf6
--- /dev/null
+++ b/public/error/index.html
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+ ZedShaw's Game Thing
+
+
+
+
+
+ 🏡 Zed's Game Dev Website Yay
+
+
+
+ ERROR
+ You have an error.
+
+
+
+
+
diff --git a/public/index.html b/public/index.html
index dea3260..33b1a24 100644
--- a/public/index.html
+++ b/public/index.html
@@ -9,7 +9,7 @@
-
+
🏡 Zed's Game Dev Website Yay
diff --git a/public/login/index.html b/public/login/index.html
new file mode 100644
index 0000000..c35e3ad
--- /dev/null
+++ b/public/login/index.html
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+ ZedShaw's Game Thing
+
+
+
+
+
+ 🏡 Zed's Game Dev Website Yay
+
+
+
+ Login
+
+
+
+
+
+
+
+
diff --git a/tests/chromedp_test.go b/tests/chromedp_test.go
index 6e617fb..1c4f2a1 100644
--- a/tests/chromedp_test.go
+++ b/tests/chromedp_test.go
@@ -1,36 +1,59 @@
package tests
import (
- "testing"
- "context"
- "time"
- "github.com/stretchr/testify/assert"
- browser "github.com/chromedp/chromedp"
+ "testing"
+ "context"
+ "log"
+ "time"
+ "github.com/stretchr/testify/assert"
+ browser "github.com/chromedp/chromedp"
)
func Run(assert *assert.Assertions, ctx context.Context, actions ...browser.Action) {
- err := browser.Run(ctx, actions...)
- assert.NoError(err)
+ err := browser.Run(ctx, actions...)
+ assert.NoError(err)
}
func Setup(timeout time.Duration) (context.Context, context.CancelFunc) {
- ctx, _ := browser.NewContext(context.Background())
- return context.WithTimeout(ctx, timeout * time.Second)
+ opts := append(browser.DefaultExecAllocatorOptions[:],
+ browser.Flag("headless", false),)
+
+ allocCtx, _ := browser.NewExecAllocator(context.Background(), opts...)
+
+ ctx, _ := browser.NewContext(allocCtx, browser.WithLogf(log.Printf))
+
+ return context.WithTimeout(ctx, timeout * time.Second)
+}
+
+func TestLogin(t *testing.T) {
+ assert := assert.New(t)
+
+ ctx, cancel := Setup(5); defer cancel()
+
+ Run(assert, ctx,
+ browser.Navigate(`http://127.0.0.1:5002/login/`),
+ browser.WaitVisible(`body > footer`),
+ browser.WaitVisible(`[data-testid="login-page"]`),
+ browser.SendKeys(`#username`, `zedshaw`),
+ browser.SendKeys(`#password`, `1234`),
+ browser.Click(`#login-submit`, browser.NodeVisible),
+ browser.WaitVisible(`body > footer`),
+ browser.WaitVisible(`[data-testid="home-page"]`))
}
func TestStreamPage(t *testing.T) {
- assert := assert.New(t)
+ assert := assert.New(t)
- ctx, cancel := Setup(20); defer cancel()
+ ctx, cancel := Setup(20); defer cancel()
- var example string
+ var example string
- Run(assert, ctx,
- browser.Navigate(`http://127.0.0.1:5002`),
- browser.WaitVisible(`body > footer`),
- browser.Click(`#streams`, browser.NodeVisible),
- browser.Text(`#streams-title`, &example))
+ Run(assert, ctx,
+ browser.Navigate(`http://127.0.0.1:5002`),
+ browser.WaitVisible(`body > footer`),
+ browser.Click(`#streams`, browser.NodeVisible),
+ browser.Text(`#streams-title`, &example))
- assert.Equal(example, "Past Streams")
+ assert.Equal(example, "Past Streams")
}