|
9 | 9 | "github.com/stretchr/testify/assert" |
10 | 10 | "k8s.io/apimachinery/pkg/util/validation/field" |
11 | 11 |
|
| 12 | + configv1 "github.com/openshift/api/config/v1" |
12 | 13 | "github.com/openshift/installer/pkg/types/powervs" |
13 | 14 | ) |
14 | 15 |
|
@@ -118,6 +119,120 @@ func TestValidatePlatform(t *testing.T) { |
118 | 119 | }(), |
119 | 120 | valid: false, |
120 | 121 | }, |
| 122 | + { |
| 123 | + name: "invalid url (no hostname) for service endpoint", |
| 124 | + platform: func() *powervs.Platform { |
| 125 | + p := validMinimalPlatform() |
| 126 | + p.ServiceEndpoints = []configv1.PowerVSServiceEndpoint{{ |
| 127 | + Name: string(configv1.IBMCloudServiceCOS), |
| 128 | + URL: "/some/path", |
| 129 | + }} |
| 130 | + return p |
| 131 | + }(), |
| 132 | + valid: false, |
| 133 | + }, |
| 134 | + { |
| 135 | + name: "invalid url (has path) for service endpoint", |
| 136 | + platform: func() *powervs.Platform { |
| 137 | + p := validMinimalPlatform() |
| 138 | + p.ServiceEndpoints = []configv1.PowerVSServiceEndpoint{{ |
| 139 | + Name: string(configv1.IBMCloudServiceCOS), |
| 140 | + URL: "https://test-cos.random.local/some/path", |
| 141 | + }} |
| 142 | + return p |
| 143 | + }(), |
| 144 | + valid: false, |
| 145 | + }, |
| 146 | + { |
| 147 | + name: "valid url (has version path, no trailing '/') for service endpoint", |
| 148 | + platform: func() *powervs.Platform { |
| 149 | + p := validMinimalPlatform() |
| 150 | + p.ServiceEndpoints = []configv1.PowerVSServiceEndpoint{{ |
| 151 | + Name: string(configv1.IBMCloudServiceCOS), |
| 152 | + URL: "https://test-cos.random.local/v2", |
| 153 | + }} |
| 154 | + return p |
| 155 | + }(), |
| 156 | + valid: true, |
| 157 | + }, |
| 158 | + { |
| 159 | + name: "valid url (has version path and trailing '/') for service endpoint", |
| 160 | + platform: func() *powervs.Platform { |
| 161 | + p := validMinimalPlatform() |
| 162 | + p.ServiceEndpoints = []configv1.PowerVSServiceEndpoint{{ |
| 163 | + Name: string(configv1.IBMCloudServiceCOS), |
| 164 | + URL: "https://test-cos.random.local/v35/", |
| 165 | + }} |
| 166 | + return p |
| 167 | + }(), |
| 168 | + valid: true, |
| 169 | + }, |
| 170 | + { |
| 171 | + name: "invalid url (has request) for service endpoint", |
| 172 | + platform: func() *powervs.Platform { |
| 173 | + p := validMinimalPlatform() |
| 174 | + p.ServiceEndpoints = []configv1.PowerVSServiceEndpoint{{ |
| 175 | + Name: string(configv1.IBMCloudServiceCOS), |
| 176 | + URL: "https://test-iam.random.local?foo=some", |
| 177 | + }} |
| 178 | + return p |
| 179 | + }(), |
| 180 | + valid: false, |
| 181 | + }, |
| 182 | + { |
| 183 | + name: "valid url (no scheme) for service endpoint", |
| 184 | + platform: func() *powervs.Platform { |
| 185 | + p := validMinimalPlatform() |
| 186 | + p.ServiceEndpoints = []configv1.PowerVSServiceEndpoint{{ |
| 187 | + Name: string(configv1.IBMCloudServiceCOS), |
| 188 | + URL: "test-cos.random.local", |
| 189 | + }} |
| 190 | + return p |
| 191 | + }(), |
| 192 | + valid: true, |
| 193 | + }, |
| 194 | + { |
| 195 | + name: "valid url (with scheme) for service endpoint", |
| 196 | + platform: func() *powervs.Platform { |
| 197 | + p := validMinimalPlatform() |
| 198 | + p.ServiceEndpoints = []configv1.PowerVSServiceEndpoint{{ |
| 199 | + Name: string(configv1.IBMCloudServiceCOS), |
| 200 | + URL: "https://test-cos.random.local", |
| 201 | + }} |
| 202 | + return p |
| 203 | + }(), |
| 204 | + valid: true, |
| 205 | + }, |
| 206 | + { |
| 207 | + name: "duplicate service endpoints", |
| 208 | + platform: func() *powervs.Platform { |
| 209 | + p := validMinimalPlatform() |
| 210 | + p.ServiceEndpoints = []configv1.PowerVSServiceEndpoint{{ |
| 211 | + Name: string(configv1.IBMCloudServiceCOS), |
| 212 | + URL: "https://test-cos.random.local", |
| 213 | + }, { |
| 214 | + Name: string(configv1.IBMCloudServiceCOS), |
| 215 | + URL: "test-cos.random.local", |
| 216 | + }} |
| 217 | + return p |
| 218 | + }(), |
| 219 | + valid: false, |
| 220 | + }, |
| 221 | + { |
| 222 | + name: "multiple valid service endpoints", |
| 223 | + platform: func() *powervs.Platform { |
| 224 | + p := validMinimalPlatform() |
| 225 | + p.ServiceEndpoints = []configv1.PowerVSServiceEndpoint{{ |
| 226 | + Name: string(configv1.IBMCloudServiceCOS), |
| 227 | + URL: "test-cos.random.local", |
| 228 | + }, { |
| 229 | + Name: string(configv1.IBMCloudServiceDNSServices), |
| 230 | + URL: "test-dns.random.local", |
| 231 | + }} |
| 232 | + return p |
| 233 | + }(), |
| 234 | + valid: true, |
| 235 | + }, |
121 | 236 | } |
122 | 237 | for _, tc := range cases { |
123 | 238 | t.Run(tc.name, func(t *testing.T) { |
|
0 commit comments