|
| 1 | +// |
| 2 | +// |
| 3 | +// Copyright Red Hat |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +// you may not use this file except in compliance with the License. |
| 7 | +// You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, software |
| 12 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +// See the License for the specific language governing permissions and |
| 15 | +// limitations under the License. |
| 16 | + |
| 17 | +package registry |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + registryv1alpha1 "github.com/devfile/registry-operator/api/v1alpha1" |
| 23 | +) |
| 24 | + |
| 25 | +func TestGetDevfileRegistryIngress(t *testing.T) { |
| 26 | + |
| 27 | + tests := []struct { |
| 28 | + name string |
| 29 | + cr registryv1alpha1.DevfileRegistry |
| 30 | + want string |
| 31 | + }{ |
| 32 | + { |
| 33 | + name: "Case 1: Correct Conjunction", |
| 34 | + cr: registryv1alpha1.DevfileRegistry{ |
| 35 | + Spec: registryv1alpha1.DevfileRegistrySpec{ |
| 36 | + K8s: registryv1alpha1.DevfileRegistrySpecK8sOnly{ |
| 37 | + IngressDomain: "my-domain", |
| 38 | + }, |
| 39 | + }}, |
| 40 | + want: "test-name-test-namespace.my-domain", |
| 41 | + }, |
| 42 | + } |
| 43 | + for _, tt := range tests { |
| 44 | + t.Run(tt.name, func(t *testing.T) { |
| 45 | + tt.cr.Name = "test-name" |
| 46 | + tt.cr.Namespace = "test-namespace" |
| 47 | + ingress := GetDevfileRegistryIngress(&tt.cr) |
| 48 | + if ingress != tt.want { |
| 49 | + t.Errorf("expected: %v got: %v", tt.want, ingress) |
| 50 | + } |
| 51 | + }) |
| 52 | + } |
| 53 | + |
| 54 | +} |
| 55 | + |
| 56 | +func TestGetHostname(t *testing.T) { |
| 57 | + |
| 58 | + tests := []struct { |
| 59 | + name string |
| 60 | + cr registryv1alpha1.DevfileRegistry |
| 61 | + want string |
| 62 | + }{ |
| 63 | + { |
| 64 | + name: "Case 1: Correct Hostname", |
| 65 | + cr: registryv1alpha1.DevfileRegistry{ |
| 66 | + Spec: registryv1alpha1.DevfileRegistrySpec{ |
| 67 | + K8s: registryv1alpha1.DevfileRegistrySpecK8sOnly{ |
| 68 | + IngressDomain: "my-domain", |
| 69 | + }, |
| 70 | + }}, |
| 71 | + want: "test-name-test-namespace", |
| 72 | + }, |
| 73 | + } |
| 74 | + for _, tt := range tests { |
| 75 | + t.Run(tt.name, func(t *testing.T) { |
| 76 | + tt.cr.Name = "test-name" |
| 77 | + tt.cr.Namespace = "test-namespace" |
| 78 | + hostname := GetHostname(&tt.cr) |
| 79 | + if hostname != tt.want { |
| 80 | + t.Errorf("expected: %v got: %v", tt.want, hostname) |
| 81 | + } |
| 82 | + }) |
| 83 | + } |
| 84 | + |
| 85 | +} |
0 commit comments