| 1 | /* |
| 2 | Copyright © 2022 Chris Mellard [email protected] |
| 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 | package credhelperscip-go gomod github.com/chrismellard/docker-credential-acr-env . `github.com/chrismellard/docker-credential-acr-env/pkg/credhelper`/ |
| 17 | |
| 18 | import "testingscip-go gomod github.com/golang/go/src go1.18 testing/" |
| 19 | |
| 20 | // TestIsACRHelper tests whether URLs are detected as being ACR/MCR registry |
| 21 | // hosts, to determine whether the cred helper should fail fast. |
| 22 | func TestIsACRHelperscip-go gomod github.com/chrismellard/docker-credential-acr-env . `github.com/chrismellard/docker-credential-acr-env/pkg/credhelper`/TestIsACRHelper().(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 23 | for _, c := range []struct { |
| 24 | url string |
| 25 | want bool |
| 26 | }{ |
| 27 | {"myregistry.azurecr.io", true}, |
| 28 | {"myregistry.azurecr.cn", true}, |
| 29 | {"myregistry.azurecr.de", true}, |
| 30 | {"myregistry.azurecr.us", true}, |
| 31 | {"mcr.microsoft.com", true}, |
| 32 | {"myregistry.azurecr.me", false}, // not a known tld |
| 33 | {"notacr.xcr.example", false}, |
| 34 | {"127.0.0.1:12345", false}, |
| 35 | {"localhost:12345", false}, |
| 36 | {"notaurl-)(*$@)(*@)(*", false}, |
| 37 | } { |
| 38 | t.Runscip-go gomod github.com/golang/go/src go1.18 testing/T#Run().(c.url, func(t *testingscip-go gomod github.com/golang/go/src go1.18 testing/.Tscip-go gomod github.com/golang/go/src go1.18 testing/T#) { |
| 39 | got := isACRRegistryscip-go gomod github.com/chrismellard/docker-credential-acr-env . `github.com/chrismellard/docker-credential-acr-env/pkg/credhelper`/isACRRegistry().(c.url) |
| 40 | if got != c.want { |
| 41 | t.Fatalfscip-go gomod github.com/golang/go/src go1.18 testing/common#Fatalf().("got %t, want %t", got, c.want) |
| 42 | } |
| 43 | }) |
| 44 | } |
| 45 | } |