convert_test.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 compatibility
  14. import (
  15. "testing"
  16. "gotest.tools/v3/assert"
  17. )
  18. func Test_convert(t *testing.T) {
  19. tests := []struct {
  20. name string
  21. args []string
  22. want []string
  23. }{
  24. {
  25. name: "compose only",
  26. args: []string{"up"},
  27. want: []string{"compose", "up"},
  28. },
  29. {
  30. name: "with context",
  31. args: []string{"--context", "foo", "-f", "compose.yaml", "up"},
  32. want: []string{"--context", "foo", "compose", "-f", "compose.yaml", "up"},
  33. },
  34. {
  35. name: "with context arg",
  36. args: []string{"--context=foo", "-f", "compose.yaml", "up"},
  37. want: []string{"--context", "foo", "compose", "-f", "compose.yaml", "up"},
  38. },
  39. {
  40. name: "with host",
  41. args: []string{"--host", "tcp://1.2.3.4", "up"},
  42. want: []string{"--host", "tcp://1.2.3.4", "compose", "up"},
  43. },
  44. {
  45. name: "compose --verbose",
  46. args: []string{"--verbose"},
  47. want: []string{"--debug", "compose"},
  48. },
  49. {
  50. name: "compose --version",
  51. args: []string{"--version"},
  52. want: []string{"compose", "version"},
  53. },
  54. {
  55. name: "compose -v",
  56. args: []string{"-v"},
  57. want: []string{"compose", "version"},
  58. },
  59. {
  60. name: "help",
  61. args: []string{"-h"},
  62. want: []string{"compose", "--help"},
  63. },
  64. {
  65. name: "issues/1962",
  66. args: []string{"psql", "-h", "postgres"},
  67. want: []string{"compose", "psql", "-h", "postgres"}, // -h should not be converted to --help
  68. },
  69. {
  70. name: "issues/8648",
  71. args: []string{"exec", "mongo", "mongo", "--host", "mongo"},
  72. want: []string{"compose", "exec", "mongo", "mongo", "--host", "mongo"}, // --host is passed to exec
  73. },
  74. {
  75. name: "issues/12",
  76. args: []string{"--log-level", "INFO", "up"},
  77. want: []string{"--log-level", "INFO", "compose", "up"},
  78. },
  79. {
  80. name: "empty string argument",
  81. args: []string{"--project-directory", "", "ps"},
  82. want: []string{"compose", "--project-directory", "", "ps"},
  83. },
  84. {
  85. name: "compose as project name",
  86. args: []string{"--project-name", "compose", "down", "--remove-orphans"},
  87. want: []string{"compose", "--project-name", "compose", "down", "--remove-orphans"},
  88. },
  89. }
  90. for _, tt := range tests {
  91. t.Run(tt.name, func(t *testing.T) {
  92. got := Convert(tt.args)
  93. assert.DeepEqual(t, tt.want, got)
  94. })
  95. }
  96. }