package provider import ( "testing" ) func TestIsECRPublicRepositoryURL(t *testing.T) { if !isECRPublicRepositoryURL("public.ecr.aws") { t.Fatalf("Expected true") } if isECRPublicRepositoryURL("public.ecr.aws.com") { t.Fatalf("Expected false") } } func TestIsECRRepositoryURL(t *testing.T) { if !isECRRepositoryURL("2385929435838.dkr.ecr.eu-central-1.amazonaws.com") { t.Fatalf("Expected true") } if !isECRRepositoryURL("39e39fmgvkgd.dkr.ecr.us-east-1.amazonaws.com") { t.Fatalf("Expected true") } if isECRRepositoryURL("39e39fmgvkgd.dkr.ecrus-east-1.amazonaws.com") { t.Fatalf("Expected false") } if !isECRRepositoryURL("public.ecr.aws") { t.Fatalf("Expected true") } } func TestParseAuthHeaders(t *testing.T) { header := "Bearer realm=\"https://gcr.io/v2/token\",service=\"gcr.io\",scope=\"repository:/:/:pull\"" result := parseAuthHeader(header) wantScope := "repository:/:/:pull" if result["scope"] != wantScope { t.Errorf("want: %#v, got: %#v", wantScope, result["scope"]) } header = "Bearer realm=\"https://gcr.io/v2/token\",service=\"gcr.io\",scope=\"repository:/:/:push,pull\"" result = parseAuthHeader(header) wantScope = "repository:/:/:push,pull" if result["scope"] != wantScope { t.Errorf("want: %#v, got: %#v", wantScope, result["scope"]) } }