helper_test.go 921 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package api_test
  2. import (
  3. "github.com/porter-dev/porter/cli/cmd/docker"
  4. )
  5. type db int
  6. const (
  7. pg db = iota
  8. sqlite
  9. )
  10. // Spins up and shuts down the Docker api server with the given options
  11. func startPorterServerWithDocker(processID string, port int, db docker.PorterDB) error {
  12. env := []string{
  13. "ADMIN_INIT=false",
  14. }
  15. startOpts := &docker.PorterStartOpts{
  16. ProcessID: processID,
  17. ServerImageTag: "testing",
  18. ServerPort: port,
  19. DB: db,
  20. KubeconfigPath: "",
  21. SkipKubeconfig: true,
  22. Env: env,
  23. }
  24. _, _, err := docker.StartPorter(startOpts)
  25. if err != nil {
  26. return err
  27. }
  28. return nil
  29. }
  30. func stopPorterServerWithDocker(processID string) error {
  31. agent, err := docker.NewAgentFromEnv()
  32. if err != nil {
  33. return err
  34. }
  35. err = agent.StopPorterContainersWithProcessID(processID)
  36. if err != nil {
  37. return err
  38. }
  39. // remove stopped containers and volumes
  40. return nil
  41. }