diff options
| author | mo khan <mo@mokhan.ca> | 2025-03-10 14:02:27 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-03-10 14:02:27 -0600 |
| commit | 782af3f62d23b5f0e36241fe7538244fb1b6730d (patch) | |
| tree | 9fca686622756667cac978dd0aca8e7e85dce155 /test | |
| parent | 5083ab853bd9c619fe750fdd6e2b3f22ab9e98dd (diff) | |
chore: add some end to end tests
Diffstat (limited to 'test')
| -rw-r--r-- | test/api_test.go | 7 | ||||
| -rw-r--r-- | test/e2e_test.go | 50 |
2 files changed, 50 insertions, 7 deletions
diff --git a/test/api_test.go b/test/api_test.go deleted file mode 100644 index 3ef4f52..0000000 --- a/test/api_test.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "testing" - -func TestHelloWorld(t *testing.T) { - // t.Fatal("not implemented") -} diff --git a/test/e2e_test.go b/test/e2e_test.go new file mode 100644 index 0000000..c25a4f8 --- /dev/null +++ b/test/e2e_test.go @@ -0,0 +1,50 @@ +package main + +import ( + "net/http" + "testing" + + "github.com/playwright-community/playwright-go" + "github.com/stretchr/testify/assert" + "github.com/xlgmokha/x/pkg/env" + "github.com/xlgmokha/x/pkg/x" +) + +func TestHelloWorld(t *testing.T) { + _ = playwright.Install() + + pw := x.Must(playwright.Run()) + browser := x.Must(pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{ + Headless: playwright.Bool(env.Fetch("HEADLESS", "true") == "true"), + SlowMo: playwright.Float(1000), + })) + page := x.Must(browser.NewPage()) + + defer func() { + x.Check(browser.Close()) + x.Check(pw.Stop()) + }() + + t.Run("SAML", func(t *testing.T) { + t.Run("IdP", func(t *testing.T) { + t.Run("provides metadata", func(t *testing.T) { + response := x.Must(http.Get("http://idp.example.com:8080/saml/metadata.xml")) + assert.Equal(t, http.StatusOK, response.StatusCode) + }) + }) + + t.Run("Service provider", func(t *testing.T) { + t.Run("provides metadata", func(t *testing.T) { + response := x.Must(http.Get("http://ui.example.com:8080/saml/metadata.xml")) + assert.Equal(t, http.StatusOK, response.StatusCode) + }) + + t.Run("starts a new session with the IdP", func(t *testing.T) { + x.Must(page.Goto("http://ui.example.com:8080/saml/new")) + action := x.Must(page.Locator("#idp-form").GetAttribute("action")) + assert.Equal(t, "http://idp.example.com:8080/saml/new", action) + assert.NoError(t, page.Locator("#submit-button").Click()) + }) + }) + }) +} |
