compose_oci_test.go 2.2 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 compose
  14. import (
  15. "testing"
  16. "go.uber.org/mock/gomock"
  17. "gotest.tools/v3/assert"
  18. "github.com/docker/compose/v5/pkg/mocks"
  19. )
  20. func TestSetEnvWithDotEnv_WithOCIArtifact(t *testing.T) {
  21. // Test that setEnvWithDotEnv doesn't fail when using OCI artifacts
  22. ctrl := gomock.NewController(t)
  23. defer ctrl.Finish()
  24. cli := mocks.NewMockCli(ctrl)
  25. opts := ProjectOptions{
  26. ConfigPaths: []string{"oci://docker.io/dockersamples/welcome-to-docker"},
  27. ProjectDir: "",
  28. EnvFiles: []string{},
  29. }
  30. err := setEnvWithDotEnv(opts, cli)
  31. assert.NilError(t, err, "setEnvWithDotEnv should not fail with OCI artifact path")
  32. }
  33. func TestSetEnvWithDotEnv_WithGitRemote(t *testing.T) {
  34. // Test that setEnvWithDotEnv doesn't fail when using Git remotes
  35. ctrl := gomock.NewController(t)
  36. defer ctrl.Finish()
  37. cli := mocks.NewMockCli(ctrl)
  38. opts := ProjectOptions{
  39. ConfigPaths: []string{"https://github.com/docker/compose.git"},
  40. ProjectDir: "",
  41. EnvFiles: []string{},
  42. }
  43. err := setEnvWithDotEnv(opts, cli)
  44. assert.NilError(t, err, "setEnvWithDotEnv should not fail with Git remote path")
  45. }
  46. func TestSetEnvWithDotEnv_WithLocalPath(t *testing.T) {
  47. // Test that setEnvWithDotEnv still works with local paths
  48. // This will fail if the file doesn't exist, but it should not panic
  49. // or produce invalid paths
  50. ctrl := gomock.NewController(t)
  51. defer ctrl.Finish()
  52. cli := mocks.NewMockCli(ctrl)
  53. opts := ProjectOptions{
  54. ConfigPaths: []string{"compose.yaml"},
  55. ProjectDir: "",
  56. EnvFiles: []string{},
  57. }
  58. // This may error if files don't exist, but should not panic
  59. _ = setEnvWithDotEnv(opts, cli)
  60. }