|
| 1 | +/* |
| 2 | +Copyright 2025 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package controller |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + "testing" |
| 22 | + |
| 23 | + . "github.com/onsi/gomega" |
| 24 | +) |
| 25 | + |
| 26 | +func Test_parseOCISource(t *testing.T) { |
| 27 | + for _, tc := range []struct { |
| 28 | + url string |
| 29 | + version string |
| 30 | + expectURL string |
| 31 | + expectVersion string |
| 32 | + }{ |
| 33 | + { |
| 34 | + url: "registry/image:v1.1.0", |
| 35 | + version: "v1.2.0", |
| 36 | + expectURL: "registry/image", |
| 37 | + expectVersion: "v1.1.0", |
| 38 | + }, |
| 39 | + { |
| 40 | + url: "registry/image", |
| 41 | + version: "v1.2.0", |
| 42 | + expectURL: "registry/image", |
| 43 | + expectVersion: "v1.2.0", |
| 44 | + }, |
| 45 | + { |
| 46 | + url: "registry:5050/image", |
| 47 | + version: "v1.2.0", |
| 48 | + expectURL: "registry:5050/image", |
| 49 | + expectVersion: "v1.2.0", |
| 50 | + }, |
| 51 | + { |
| 52 | + url: "registry:5050/image:v1.1.0", |
| 53 | + version: "v1.2.0", |
| 54 | + expectURL: "registry:5050/image", |
| 55 | + expectVersion: "v1.1.0", |
| 56 | + }, |
| 57 | + { |
| 58 | + url: "image", |
| 59 | + version: "v1.2.0", |
| 60 | + expectURL: "image", |
| 61 | + expectVersion: "v1.2.0", |
| 62 | + }, |
| 63 | + } { |
| 64 | + t.Run(tc.url, func(t *testing.T) { |
| 65 | + g := NewWithT(t) |
| 66 | + |
| 67 | + { |
| 68 | + url, version, plainHTTP := parseOCISource(tc.url, tc.version) |
| 69 | + g.Expect(url).To(Equal(tc.expectURL)) |
| 70 | + g.Expect(version).To(Equal(tc.expectVersion)) |
| 71 | + g.Expect(plainHTTP).To(BeFalse()) |
| 72 | + } |
| 73 | + |
| 74 | + { |
| 75 | + url, version, plainHTTP := parseOCISource(fmt.Sprintf("http://%s", tc.url), tc.version) |
| 76 | + g.Expect(url).To(Equal(tc.expectURL)) |
| 77 | + g.Expect(version).To(Equal(tc.expectVersion)) |
| 78 | + g.Expect(plainHTTP).To(BeTrue()) |
| 79 | + } |
| 80 | + }) |
| 81 | + } |
| 82 | +} |
0 commit comments