manifest_test.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. Copyright 2019 The Kubernetes 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 image
  14. import (
  15. "fmt"
  16. "testing"
  17. )
  18. type result struct {
  19. result string
  20. err error
  21. }
  22. var registryTests = []struct {
  23. in string
  24. out result
  25. }{
  26. {
  27. "docker.io/library/test:123",
  28. result{
  29. result: "test.io/library/test:123",
  30. err: nil,
  31. },
  32. },
  33. {
  34. "docker.io/library/test",
  35. result{
  36. result: "test.io/library/test",
  37. err: nil,
  38. },
  39. },
  40. {
  41. "test",
  42. result{
  43. result: "test.io/library/test",
  44. err: nil,
  45. },
  46. },
  47. {
  48. "gcr.io/kubernetes-e2e-test-images/test:123",
  49. result{
  50. result: "test.io/kubernetes-e2e-test-images/test:123",
  51. err: nil,
  52. },
  53. },
  54. {
  55. "k8s.gcr.io/test:123",
  56. result{
  57. result: "test.io/test:123",
  58. err: nil,
  59. },
  60. },
  61. {
  62. "gcr.io/k8s-authenticated-test/test:123",
  63. result{
  64. result: "test.io/k8s-authenticated-test/test:123",
  65. err: nil,
  66. },
  67. },
  68. {
  69. "gcr.io/gke-release/test:latest",
  70. result{
  71. result: "test.io/gke-release/test:latest",
  72. err: nil,
  73. },
  74. },
  75. {
  76. "gcr.io/google-samples/test:latest",
  77. result{
  78. result: "test.io/google-samples/test:latest",
  79. err: nil,
  80. },
  81. },
  82. {
  83. "quay.io/k8scsi/test:latest",
  84. result{
  85. result: "test.io/k8scsi/test:latest",
  86. err: nil,
  87. },
  88. },
  89. {
  90. "unknwon.io/google-samples/test:latest",
  91. result{
  92. result: "",
  93. err: fmt.Errorf("Registry: unknwon.io/google-samples is missing in test/utils/image/manifest.go, please add the registry, otherwise the test will fail on air-gapped clusters"),
  94. },
  95. },
  96. }
  97. // ToDo Add Benchmark
  98. func TestReplaceRegistryInImageURL(t *testing.T) {
  99. // Set custom registries
  100. dockerLibraryRegistry = "test.io/library"
  101. e2eRegistry = "test.io/kubernetes-e2e-test-images"
  102. gcRegistry = "test.io"
  103. gcrReleaseRegistry = "test.io/gke-release"
  104. PrivateRegistry = "test.io/k8s-authenticated-test"
  105. sampleRegistry = "test.io/google-samples"
  106. quayK8sCSI = "test.io/k8scsi"
  107. for _, tt := range registryTests {
  108. t.Run(tt.in, func(t *testing.T) {
  109. s, err := ReplaceRegistryInImageURL(tt.in)
  110. if err != nil && err.Error() != tt.out.err.Error() {
  111. t.Errorf("got %q, want %q", err, tt.out.err)
  112. }
  113. if s != tt.out.result {
  114. t.Errorf("got %q, want %q", s, tt.out.result)
  115. }
  116. })
  117. }
  118. }