pat_suggest_test.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 mobycli
  14. import (
  15. "testing"
  16. "github.com/docker/docker/registry"
  17. "gotest.tools/assert"
  18. )
  19. func TestIsUsingDefaultRegistry(t *testing.T) {
  20. testCases := []struct {
  21. name string
  22. input []string
  23. expected bool
  24. }{
  25. {
  26. "without flags",
  27. []string{"login"},
  28. true,
  29. },
  30. {
  31. "login with flags",
  32. []string{"login", "-u", "test", "-p", "testpass"},
  33. true,
  34. },
  35. {
  36. "login to default registry",
  37. []string{"login", registry.IndexServer},
  38. true,
  39. },
  40. {
  41. "login to different registry",
  42. []string{"login", "registry.example.com"},
  43. false,
  44. },
  45. {
  46. "login with flags to different registry",
  47. []string{"login", "-u", "test", "-p", "testpass", "registry.example.com"},
  48. false,
  49. },
  50. }
  51. for _, testCase := range testCases {
  52. t.Run(testCase.name, func(t *testing.T) {
  53. result := isUsingDefaultRegistry(testCase.input)
  54. assert.Equal(t, testCase.expected, result)
  55. })
  56. }
  57. }
  58. func TestIsUsingPassword(t *testing.T) {
  59. testCases := []struct {
  60. name string
  61. input string
  62. expected bool
  63. }{
  64. {
  65. "regular password",
  66. "mypass",
  67. true,
  68. },
  69. {
  70. "no password or sso",
  71. "",
  72. false,
  73. },
  74. {
  75. "personal access token",
  76. "1508b8bd-b80c-452d-9a7a-ee5607c41bcd",
  77. false,
  78. },
  79. {
  80. "prefixed personal access token",
  81. "dckrp_ee5607c41bcd",
  82. false,
  83. },
  84. }
  85. for _, testCase := range testCases {
  86. t.Run(testCase.name, func(t *testing.T) {
  87. result := isUsingPassword(testCase.input)
  88. assert.Equal(t, testCase.expected, result)
  89. })
  90. }
  91. }