authelia/suites/docker.go
Clement Michaud a991379a74 Declare suites as Go structs and bootstrap e2e test framework in Go.
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.
2019-11-15 20:23:06 +01:00

54 lines
1.6 KiB
Go

package suites
import (
"os"
"os/exec"
"strings"
"github.com/clems4ever/authelia/utils"
log "github.com/sirupsen/logrus"
)
// DockerEnvironment represent a docker environment
type DockerEnvironment struct {
dockerComposeFiles []string
}
// NewDockerEnvironment create a new docker environment
func NewDockerEnvironment(files []string) *DockerEnvironment {
return &DockerEnvironment{dockerComposeFiles: files}
}
func (de *DockerEnvironment) createCommandWithStdout(cmd string) *exec.Cmd {
dockerCmdLine := "docker-compose -f " + strings.Join(de.dockerComposeFiles, " -f ") + " " + cmd
log.Trace(dockerCmdLine)
return utils.CommandWithStdout("bash", "-c", dockerCmdLine)
}
func (de *DockerEnvironment) createCommand(cmd string) *exec.Cmd {
dockerCmdLine := "docker-compose -f " + strings.Join(de.dockerComposeFiles, " -f ") + " " + cmd
log.Trace(dockerCmdLine)
return exec.Command("bash", "-c", dockerCmdLine)
}
// Up spawn a docker environment
func (de *DockerEnvironment) Up(suitePath string) error {
cmd := de.createCommandWithStdout("up -d")
cmd.Env = append(os.Environ(), "SUITE_PATH="+suitePath)
return cmd.Run()
}
// Down spawn a docker environment
func (de *DockerEnvironment) Down(suitePath string) error {
cmd := de.createCommandWithStdout("down -v")
cmd.Env = append(os.Environ(), "SUITE_PATH="+suitePath)
return cmd.Run()
}
// Logs get logs of a given service of the environment
func (de *DockerEnvironment) Logs(service string, flags []string) (string, error) {
cmd := de.createCommand("logs " + strings.Join(flags, " ") + " " + service)
content, err := cmd.Output()
return string(content), err
}