k8s.io/registry.k8s.io@v0.3.1/cmd/archeio/internal/app/buckets_test.go (about) 1 /* 2 Copyright 2022 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 app 18 19 import ( 20 "strings" 21 "testing" 22 23 "k8s.io/registry.k8s.io/pkg/net/cloudcidrs" 24 ) 25 26 func TestRegionToAWSRegionToHostURL(t *testing.T) { 27 // ensure known regions return a configured bucket 28 regions := []string{} 29 for _, ipInfo := range cloudcidrs.AllIPInfos() { 30 // AWS regions, excluding "GLOBAL" meta region, AWS US Gov Cloud and European Soveign Cloud 31 if ipInfo.Cloud == cloudcidrs.AWS && 32 ipInfo.Region != "GLOBAL" && !strings.HasPrefix(ipInfo.Region, "us-gov-") && !strings.HasPrefix(ipInfo.Region, "eusc-") { 33 regions = append(regions, ipInfo.Region) 34 } 35 } 36 for _, region := range regions { 37 url := awsRegionToHostURL(region, "") 38 if url == "" { 39 t.Fatalf("received empty string for known region %q", region) 40 } 41 } 42 // test default region 43 if url := awsRegionToHostURL("nonsensical-region", "____default____"); url != "____default____" { 44 t.Fatalf("received non-empty URL string for made up region \"nonsensical-region\": %q", url) 45 } 46 } 47 48 func TestBlobCache(t *testing.T) { 49 bc := &blobCache{} 50 bc.Put("foo") 51 if !bc.Get("foo") { 52 t.Fatal("Cache did not contain key we just put") 53 } 54 if bc.Get("bar") { 55 t.Fatal("Cache contained key we did not put") 56 } 57 }