github.com/defang-io/defang/src@v0.0.0-20240505002154-bdf411911834/pkg/clouds/aws/ecs/cfn/template_test.go (about) 1 package cfn 2 3 import "testing" 4 5 func TestGetCacheRepoPrefix(t *testing.T) { 6 // Test cases 7 tests := []struct { 8 prefix string 9 suffix string 10 want string 11 }{ 12 { 13 prefix: "short-", 14 suffix: "ecr-public", 15 want: "short-ecr-public", 16 }, 17 { 18 prefix: "short-", 19 suffix: "docker-public", 20 want: "short-docker-public", 21 }, 22 { 23 prefix: "loooooooooong-", 24 suffix: "docker-public", 25 want: "fab852-docker-public", 26 }, 27 } 28 for _, tt := range tests { 29 t.Run(tt.want, func(t *testing.T) { 30 if got := getCacheRepoPrefix(tt.prefix, tt.suffix); got != tt.want { 31 t.Errorf("getCacheRepoPrefix() = %q, want %q", got, tt.want) 32 } else if len(got) > maxCachePrefixLength { 33 t.Errorf("getCacheRepoPrefix() = %q, want length <= %v", got, maxCachePrefixLength) 34 } 35 }) 36 } 37 }