mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
a991379a74
Some tests are not fully rewritten in Go, a typescript wrapper is called instead until we remove the remaining TS tests and dependencies. Also, dockerize every components (mainly Authelia backend, frontend and kind) so that the project does not interfere with user host anymore (open ports for instance). The only remaining intrusive change is the one done during bootstrap to add entries in /etc/hosts. It will soon be avoided using authelia.com domain that I own.
102 lines
2.7 KiB
Go
102 lines
2.7 KiB
Go
package suites
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/clems4ever/authelia/utils"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/suite"
|
|
"github.com/tebeka/selenium"
|
|
)
|
|
|
|
// SeleniumSuite is a selenium suite
|
|
type SeleniumSuite struct {
|
|
suite.Suite
|
|
|
|
*WebDriverSession
|
|
}
|
|
|
|
// WebDriver return the webdriver of the suite
|
|
func (s *SeleniumSuite) WebDriver() selenium.WebDriver {
|
|
return s.WebDriverSession.WebDriver
|
|
}
|
|
|
|
// Wait wait until condition holds true
|
|
func (s *SeleniumSuite) Wait(ctx context.Context, condition selenium.Condition) error {
|
|
done := make(chan error, 1)
|
|
go func() {
|
|
done <- s.WebDriverSession.WebDriver.Wait(condition)
|
|
}()
|
|
|
|
select {
|
|
case <-ctx.Done():
|
|
return errors.New("waiting timeout reached")
|
|
case err := <-done:
|
|
return err
|
|
}
|
|
}
|
|
|
|
func rootPath() string {
|
|
rootPath := os.Getenv("ROOT_PATH")
|
|
|
|
// If env variable is not provided, use relative path.
|
|
if rootPath == "" {
|
|
rootPath = ".."
|
|
}
|
|
return rootPath
|
|
}
|
|
|
|
func relativePath(path string) string {
|
|
return fmt.Sprintf("%s/%s", rootPath(), path)
|
|
}
|
|
|
|
// RunTypescriptSuite run the tests of the typescript suite
|
|
func RunTypescriptSuite(t *testing.T, suite string) {
|
|
forbidFlags := ""
|
|
if os.Getenv("ONLY_FORBIDDEN") == "true" {
|
|
forbidFlags = "--forbid-only --forbid-pending"
|
|
}
|
|
|
|
cmdline := "./node_modules/.bin/mocha" +
|
|
" --exit --require ts-node/register " + forbidFlags + " " +
|
|
fmt.Sprintf("test/suites/%s/test.ts", suite)
|
|
|
|
command := utils.CommandWithStdout("bash", "-c", cmdline)
|
|
command.Dir = rootPath()
|
|
command.Env = append(
|
|
os.Environ(),
|
|
"ENVIRONMENT=dev",
|
|
fmt.Sprintf("TS_NODE_PROJECT=%s", "test/tsconfig.json"))
|
|
|
|
assert.NoError(t, command.Run())
|
|
}
|
|
|
|
// SetupTeardown binding setup and teardown functors
|
|
type SetupTeardown struct {
|
|
Setup func(suitePath string) error
|
|
Teardown func(suitePath string) error
|
|
}
|
|
|
|
// CreateTypescriptSetupTeardown create a setup and teardown functor from the suite name
|
|
func CreateTypescriptSetupTeardown(suite string) SetupTeardown {
|
|
setup := func(suitePath string) error {
|
|
cmdline := "./node_modules/.bin/ts-node -P test/tsconfig.json -- ./scripts/setup-environment.ts " + suite
|
|
command := utils.CommandWithStdout("bash", "-c", cmdline)
|
|
command.Env = append(os.Environ(), "ENVIRONMENT=dev", fmt.Sprintf("SUITE_PATH=%s", suitePath))
|
|
return command.Run()
|
|
}
|
|
|
|
teardown := func(suitePath string) error {
|
|
cmdline := "./node_modules/.bin/ts-node -P test/tsconfig.json -- ./scripts/teardown-environment.ts " + suite
|
|
command := utils.CommandWithStdout("bash", "-c", cmdline)
|
|
command.Env = append(os.Environ(), "ENVIRONMENT=dev", fmt.Sprintf("SUITE_PATH=%s", suitePath))
|
|
return command.Run()
|
|
}
|
|
|
|
return SetupTeardown{Setup: setup, Teardown: teardown}
|
|
}
|