helper.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package framework
  2. import (
  3. "fmt"
  4. "log"
  5. "os"
  6. "strings"
  7. "github.com/robpike/filter"
  8. "github.com/onsi/gomega"
  9. )
  10. func nonEmptyString(s string) bool {
  11. return strings.TrimSpace(s) != ""
  12. }
  13. //Lines get lines from a raw string
  14. func Lines(output string) []string {
  15. return filter.Choose(strings.Split(output, "\n"), nonEmptyString).([]string)
  16. }
  17. //Columns get columns from a line
  18. func Columns(line string) []string {
  19. return filter.Choose(strings.Split(line, " "), nonEmptyString).([]string)
  20. }
  21. // It runs func
  22. func It(description string, test func()) {
  23. test()
  24. log.Print("Passed: ", description)
  25. }
  26. func gomegaFailHandler(message string, callerSkip ...int) {
  27. log.Fatal(message)
  28. }
  29. //SetupTest Init gomega fail handler
  30. func SetupTest() {
  31. gomega.RegisterFailHandler(gomegaFailHandler)
  32. linkClassicDocker()
  33. }
  34. func linkClassicDocker() {
  35. dockerOriginal := strings.TrimSuffix(NewCommand("which", "docker").ExecOrDie(), "\n")
  36. _, err := NewCommand("rm", "-r", "./bin/tests").Exec()
  37. if err == nil {
  38. fmt.Println("Removing existing /bin/tests folder before running tests")
  39. }
  40. _, err = NewCommand("mkdir", "-p", "./bin/tests").Exec()
  41. gomega.Expect(err).To(gomega.BeNil())
  42. NewCommand("ln", "-s", dockerOriginal, "./bin/tests/docker-classic").ExecOrDie()
  43. newPath := "./bin/tests:" + os.Getenv("PATH")
  44. err = os.Setenv("PATH", newPath)
  45. gomega.Expect(err).To(gomega.BeNil())
  46. }