pull_test.go 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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, "Image alpine:3.14 Pulled"))
  28. assert.Assert(t, strings.Contains(output, "Image alpine:3.15 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, "Image alpine:3.14 Pulled"))
  33. assert.Assert(t, strings.Contains(output, "Image alpine:3.15 Pulled"))
  34. })
  35. t.Run("Verify skipped pull if image is already present locally", func(t *testing.T) {
  36. // make sure the required image is present
  37. c.RunDockerComposeCmd(t, "--project-directory", "fixtures/compose-pull/image-present-locally", "pull")
  38. res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/compose-pull/image-present-locally", "pull")
  39. output := res.Combined()
  40. assert.Assert(t, strings.Contains(output, "alpine:3.13.12 Skipped Image is already present locally"))
  41. // image with :latest tag gets pulled regardless if pull_policy: missing or if_not_present
  42. assert.Assert(t, strings.Contains(output, "alpine:latest Pulled"))
  43. })
  44. t.Run("Verify skipped no image to be pulled", func(t *testing.T) {
  45. res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/compose-pull/no-image-name-given", "pull")
  46. output := res.Combined()
  47. assert.Assert(t, strings.Contains(output, "Skipped No image to be pulled"))
  48. })
  49. t.Run("Verify pull failure", func(t *testing.T) {
  50. res := c.RunDockerComposeCmdNoCheck(t, "--project-directory", "fixtures/compose-pull/unknown-image", "pull")
  51. res.Assert(t, icmd.Expected{ExitCode: 1, Err: "pull access denied for does_not_exists"})
  52. })
  53. t.Run("Verify ignore pull failure", func(t *testing.T) {
  54. res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/compose-pull/unknown-image", "pull", "--ignore-pull-failures")
  55. res.Assert(t, icmd.Expected{Err: "Some service image(s) must be built from source by running:"})
  56. })
  57. }