pull_test.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. Copyright 2020 Docker Compose CLI authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package e2e
  14. import (
  15. "strings"
  16. "testing"
  17. "gotest.tools/v3/assert"
  18. "gotest.tools/v3/icmd"
  19. )
  20. func TestComposePull(t *testing.T) {
  21. c := NewParallelCLI(t)
  22. t.Run("Verify image pulled", func(t *testing.T) {
  23. // cleanup existing images
  24. c.RunDockerComposeCmd(t, "--project-directory", "fixtures/compose-pull/simple", "down", "--rmi", "all")
  25. res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/compose-pull/simple", "pull")
  26. output := res.Combined()
  27. assert.Assert(t, strings.Contains(output, "simple Pulled"))
  28. assert.Assert(t, strings.Contains(output, "another Pulled"))
  29. // verify default policy is 'always' for pull command
  30. res = c.RunDockerComposeCmd(t, "--project-directory", "fixtures/compose-pull/simple", "pull")
  31. output = res.Combined()
  32. assert.Assert(t, strings.Contains(output, "simple Pulled"))
  33. assert.Assert(t, strings.Contains(output, "another Pulled"))
  34. })
  35. t.Run("Verify a image is pulled once", func(t *testing.T) {
  36. // cleanup existing images
  37. c.RunDockerComposeCmd(t, "--project-directory", "fixtures/compose-pull/duplicate-images", "down", "--rmi", "all")
  38. res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/compose-pull/duplicate-images", "pull")
  39. output := res.Combined()
  40. if strings.Contains(output, "another Pulled") {
  41. assert.Assert(t, strings.Contains(output, "another Pulled"))
  42. assert.Assert(t, strings.Contains(output, "Skipped - Image is already being pulled by another"))
  43. } else {
  44. assert.Assert(t, strings.Contains(output, "simple Pulled"))
  45. assert.Assert(t, strings.Contains(output, "Skipped - Image is already being pulled by simple"))
  46. }
  47. })
  48. t.Run("Verify skipped pull if image is already present locally", func(t *testing.T) {
  49. // make sure the required image is present
  50. c.RunDockerComposeCmd(t, "--project-directory", "fixtures/compose-pull/image-present-locally", "pull")
  51. res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/compose-pull/image-present-locally", "pull")
  52. output := res.Combined()
  53. assert.Assert(t, strings.Contains(output, "simple Skipped - Image is already present locally"))
  54. // image with :latest tag gets pulled regardless if pull_policy: missing or if_not_present
  55. assert.Assert(t, strings.Contains(output, "latest Pulled"))
  56. })
  57. t.Run("Verify skipped no image to be pulled", func(t *testing.T) {
  58. res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/compose-pull/no-image-name-given", "pull")
  59. output := res.Combined()
  60. assert.Assert(t, strings.Contains(output, "Skipped - No image to be pulled"))
  61. })
  62. t.Run("Verify pull failure", func(t *testing.T) {
  63. res := c.RunDockerComposeCmdNoCheck(t, "--project-directory", "fixtures/compose-pull/unknown-image", "pull")
  64. res.Assert(t, icmd.Expected{ExitCode: 18, Err: "pull access denied for does_not_exists"})
  65. })
  66. t.Run("Verify ignore pull failure", func(t *testing.T) {
  67. res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/compose-pull/unknown-image", "pull", "--ignore-pull-failures")
  68. res.Assert(t, icmd.Expected{Err: "Some service image(s) must be built from source by running:"})
  69. })
  70. }