e2e.go 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package main
  2. import (
  3. "log"
  4. "strings"
  5. "time"
  6. "github.com/robpike/filter"
  7. f "github.com/docker/api/tests/framework"
  8. g "github.com/onsi/gomega"
  9. )
  10. func main() {
  11. setup()
  12. It("ensures context command includes azure-login and aci-create", func() {
  13. output := f.NewDockerCommand("context", "create", "--help").ExecOrDie()
  14. g.Expect(output).To(g.ContainSubstring("docker context create CONTEXT BACKEND [OPTIONS] [flags]"))
  15. g.Expect(output).To(g.ContainSubstring("--aci-location"))
  16. g.Expect(output).To(g.ContainSubstring("--aci-subscription-id"))
  17. g.Expect(output).To(g.ContainSubstring("--aci-resource-group"))
  18. })
  19. It("should be initialized with default context", func() {
  20. f.NewCommand("docker", "context", "use", "default").ExecOrDie()
  21. output := f.NewCommand("docker", "context", "ls").ExecOrDie()
  22. g.Expect(output).To(g.ContainSubstring("default *"))
  23. })
  24. It("should list all legacy commands", func() {
  25. output := f.NewDockerCommand("--help").ExecOrDie()
  26. g.Expect(output).To(g.ContainSubstring("swarm"))
  27. })
  28. It("should execute legacy commands", func() {
  29. output, _ := f.NewDockerCommand("swarm", "join").Exec()
  30. g.Expect(output).To(g.ContainSubstring("\"docker swarm join\" requires exactly 1 argument."))
  31. })
  32. It("should run local container in less than 2 secs", func() {
  33. f.NewDockerCommand("pull", "hello-world").ExecOrDie()
  34. output := f.NewDockerCommand("run", "hello-world").WithTimeout(time.NewTimer(2 * time.Second).C).ExecOrDie()
  35. g.Expect(output).To(g.ContainSubstring("Hello from Docker!"))
  36. })
  37. It("should list local container", func() {
  38. output := f.NewDockerCommand("ps", "-a").ExecOrDie()
  39. g.Expect(output).To(g.ContainSubstring("hello-world"))
  40. })
  41. It("creates a new test context to hardcoded example backend", func() {
  42. f.NewDockerCommand("context", "create", "test-example", "example").ExecOrDie()
  43. //g.Expect(output).To(g.ContainSubstring("test-example context acitest created"))
  44. })
  45. defer f.NewCommand("docker", "context", "rm", "test-example", "-f").ExecOrDie()
  46. It("uses the test context", func() {
  47. currentContext := f.NewCommand("docker", "context", "use", "test-example").ExecOrDie()
  48. g.Expect(currentContext).To(g.ContainSubstring("test-example"))
  49. output := f.NewCommand("docker", "context", "ls").ExecOrDie()
  50. g.Expect(output).To(g.ContainSubstring("test-example *"))
  51. })
  52. It("can run ps command", func() {
  53. output := f.NewDockerCommand("ps").ExecOrDie()
  54. lines := lines(output)
  55. g.Expect(len(lines)).To(g.Equal(3))
  56. g.Expect(lines[2]).To(g.ContainSubstring("1234 alpine"))
  57. })
  58. It("can run 'run' command", func() {
  59. output := f.NewDockerCommand("run", "nginx", "-p", "80:80").ExecOrDie()
  60. g.Expect(output).To(g.ContainSubstring("Running container \"nginx\" with name"))
  61. })
  62. }
  63. func nonEmptyString(s string) bool {
  64. return strings.TrimSpace(s) != ""
  65. }
  66. func lines(output string) []string {
  67. return filter.Choose(strings.Split(output, "\n"), nonEmptyString).([]string)
  68. }
  69. // It runs func
  70. func It(description string, test func()) {
  71. test()
  72. log.Print("Passed: ", description)
  73. }
  74. func gomegaFailHandler(message string, callerSkip ...int) {
  75. log.Fatal(message)
  76. }
  77. func setup() {
  78. g.RegisterFailHandler(gomegaFailHandler)
  79. }