/* Copyright © 2022 Chris Mellard chris.mellard@icloud.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package credhelper import "testing" // TestIsACRHelper tests whether URLs are detected as being ACR/MCR registry // hosts, to determine whether the cred helper should fail fast. func TestIsACRHelper(t *testing.T) { for _, c := range []struct { url string want bool }{ {"myregistry.azurecr.io", true}, {"myregistry.azurecr.cn", true}, {"myregistry.azurecr.de", true}, {"myregistry.azurecr.us", true}, {"mcr.microsoft.com", true}, {"myregistry.azurecr.me", false}, // not a known tld {"notacr.xcr.example", false}, {"127.0.0.1:12345", false}, {"localhost:12345", false}, {"notaurl-)(*$@)(*@)(*", false}, } { t.Run(c.url, func(t *testing.T) { got := isACRRegistry(c.url) if got != c.want { t.Fatalf("got %t, want %t", got, c.want) } }) } }