miniauth/main_test.go
2025-03-14 02:52:18 +01:00

39 lines
1 KiB
Go

package main
import (
"net/http"
"net/http/httptest"
"os"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
)
func TestStartpageEmpty(t *testing.T) {
name, err := os.MkdirTemp("", "miniauth-teststore")
assert.Nil(t, err, "[setup] should be abel to create tmp dir")
gc := gloableConfig{}
gc.UserStoreConfig.SQLite.Path = "file:" + name + "/" + uuid.NewString() + ".sqlite"
router := setupRouter(gc)
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/", nil)
router.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
assert.Equal(t, "", w.Body.String())
}
func TestPingRoute(t *testing.T) {
name, err := os.MkdirTemp("", "miniauth-teststore")
assert.Nil(t, err, "[setup] should be abel to create tmp dir")
gc := gloableConfig{}
gc.UserStoreConfig.SQLite.Path = "file:" + name + "/" + uuid.NewString() + ".sqlite"
router := setupRouter(gc)
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/ping", nil)
router.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
assert.Equal(t, "pong", w.Body.String())
}