1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-16 11:37:36 +02:00
ferret/e2e/main.go
2018-11-12 14:53:36 -05:00

92 lines
1.6 KiB
Go

package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"github.com/MontFerret/ferret/e2e/runner"
"github.com/MontFerret/ferret/e2e/server"
"github.com/rs/zerolog"
)
var (
testsDir = flag.String(
"tests",
"./tests",
"root directory with test scripts",
)
pagesDir = flag.String(
"pages",
"./pages",
"root directory with test pages",
)
cdp = flag.String(
"cdp",
"http://0.0.0.0:9222",
"address of remote Chrome instance",
)
)
func main() {
flag.Parse()
logger := zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr})
staticPort := uint64(8080)
static := server.New(server.Settings{
Port: staticPort,
Dir: filepath.Join(*pagesDir, "static"),
})
dynamicPort := uint64(8081)
dynamic := server.New(server.Settings{
Port: dynamicPort,
Dir: filepath.Join(*pagesDir, "dynamic"),
})
go func() {
if err := static.Start(); err != nil {
logger.Info().Timestamp().Msg("shutting down the static pages server")
}
}()
go func() {
if err := dynamic.Start(); err != nil {
logger.Info().Timestamp().Msg("shutting down the dynamic pages server")
}
}()
dirname := *testsDir
if dirname == "" {
d, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
logger.Fatal().Timestamp().Err(err).Msg("failed to get testsDir")
return
}
dirname = d
}
r := runner.New(logger, runner.Settings{
StaticServerAddress: fmt.Sprintf("http://0.0.0.0:%d", staticPort),
DynamicServerAddress: fmt.Sprintf("http://0.0.0.0:%d", dynamicPort),
CDPAddress: *cdp,
Dir: *testsDir,
})
err := r.Run()
if err != nil {
os.Exit(1)
}
os.Exit(0)
}