Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove deprecated SplitHostname #5

Merged
merged 1 commit into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions normalize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,62 +466,62 @@ func TestNormalizedSplitHostname(t *testing.T) {
tests := []struct {
input string
domain string
name string
path string
}{
{
input: "test.com/foo",
domain: "test.com",
name: "foo",
path: "foo",
},
{
input: "test_com/foo",
domain: "docker.io",
name: "test_com/foo",
path: "test_com/foo",
},
{
input: "docker/migrator",
domain: "docker.io",
name: "docker/migrator",
path: "docker/migrator",
},
{
input: "test.com:8080/foo",
domain: "test.com:8080",
name: "foo",
path: "foo",
},
{
input: "test-com:8080/foo",
domain: "test-com:8080",
name: "foo",
path: "foo",
},
{
input: "foo",
domain: "docker.io",
name: "library/foo",
path: "library/foo",
},
{
input: "xn--n3h.com/foo",
domain: "xn--n3h.com",
name: "foo",
path: "foo",
},
{
input: "xn--n3h.com:18080/foo",
domain: "xn--n3h.com:18080",
name: "foo",
path: "foo",
},
{
input: "docker.io/foo",
domain: "docker.io",
name: "library/foo",
path: "library/foo",
},
{
input: "docker.io/library/foo",
domain: "docker.io",
name: "library/foo",
path: "library/foo",
},
{
input: "docker.io/library/foo/bar",
domain: "docker.io",
name: "library/foo/bar",
path: "library/foo/bar",
},
}
for _, tc := range tests {
Expand All @@ -532,12 +532,12 @@ func TestNormalizedSplitHostname(t *testing.T) {
if err != nil {
t.Errorf("error parsing name: %s", err)
}
domain, name := SplitHostname(named) //nolint:staticcheck // Ignore SA1019: SplitHostname is deprecated.
if domain != tc.domain {

if domain := Domain(named); domain != tc.domain {
t.Errorf("unexpected domain: got %q, expected %q", domain, tc.domain)
}
if name != tc.name {
t.Errorf("unexpected name: got %q, expected %q", name, tc.name)
if path := Path(named); path != tc.path {
t.Errorf("unexpected name: got %q, expected %q", path, tc.path)
}
})
}
Expand Down
16 changes: 3 additions & 13 deletions reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ func Path(named Named) (name string) {
return path
}

// splitDomain splits a named reference into a hostname and path string.
// If no valid hostname is found, the hostname is empty and the full value
// is returned as name
func splitDomain(name string) (string, string) {
match := anchoredNameRegexp.FindStringSubmatch(name)
if len(match) != 3 {
Expand All @@ -173,19 +176,6 @@ func splitDomain(name string) (string, string) {
return match[1], match[2]
}

// SplitHostname splits a named reference into a
// hostname and name string. If no valid hostname is
// found, the hostname is empty and the full value
// is returned as name
//
// Deprecated: Use [Domain] or [Path].
func SplitHostname(named Named) (string, string) {
if r, ok := named.(namedRepository); ok {
return r.Domain(), r.Path()
}
return splitDomain(named.Name())
}

// Parse parses s and returns a syntactically valid Reference.
// If an error was encountered it is returned, along with a nil Reference.
func Parse(s string) (Reference, error) {
Expand Down
41 changes: 19 additions & 22 deletions reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ func TestReferenceParse(t *testing.T) {
if named.Name() != tc.repository {
t.Errorf("unexpected repository: got %q, expected %q", named.Name(), tc.repository)
}
domain, _ := SplitHostname(named)
if domain != tc.domain {
if domain := Domain(named); domain != tc.domain {
t.Errorf("unexpected domain: got %q, expected %q", domain, tc.domain)
}
} else if tc.repository != "" || tc.domain != "" {
Expand Down Expand Up @@ -373,42 +372,42 @@ func TestWithNameFailure(t *testing.T) {
}
}

func TestSplitHostname(t *testing.T) {
func TestDomainAndPath(t *testing.T) {
t.Parallel()
tests := []struct {
input string
domain string
name string
path string
}{
{
input: "test.com/foo",
domain: "test.com",
name: "foo",
path: "foo",
},
{
input: "test_com/foo",
domain: "",
name: "test_com/foo",
path: "test_com/foo",
},
{
input: "test:8080/foo",
domain: "test:8080",
name: "foo",
path: "foo",
},
{
input: "test.com:8080/foo",
domain: "test.com:8080",
name: "foo",
path: "foo",
},
{
input: "test-com:8080/foo",
domain: "test-com:8080",
name: "foo",
path: "foo",
},
{
input: "xn--n3h.com:18080/foo",
domain: "xn--n3h.com:18080",
name: "foo",
path: "foo",
},
}
for _, tc := range tests {
Expand All @@ -419,12 +418,11 @@ func TestSplitHostname(t *testing.T) {
if err != nil {
t.Errorf("error parsing name: %s", err)
}
domain, name := SplitHostname(named)
if domain != tc.domain {
if domain := Domain(named); domain != tc.domain {
t.Errorf("unexpected domain: got %q, expected %q", domain, tc.domain)
}
if name != tc.name {
t.Errorf("unexpected name: got %q, expected %q", name, tc.name)
if path := Path(named); path != tc.path {
t.Errorf("unexpected name: got %q, expected %q", path, tc.path)
}
})
}
Expand Down Expand Up @@ -681,18 +679,18 @@ func TestParseNamed(t *testing.T) {
tests := []struct {
input string
domain string
name string
path string
err error
}{
{
input: "test.com/foo",
domain: "test.com",
name: "foo",
path: "foo",
},
{
input: "test:8080/foo",
domain: "test:8080",
name: "foo",
path: "foo",
},
{
input: "test_com/foo",
Expand All @@ -713,7 +711,7 @@ func TestParseNamed(t *testing.T) {
{
input: "docker.io/library/foo",
domain: "docker.io",
name: "library/foo",
path: "library/foo",
},
// Ambiguous case, parser will add "library/" to foo
{
Expand All @@ -739,12 +737,11 @@ func TestParseNamed(t *testing.T) {
return
}

domain, name := SplitHostname(named)
if domain != tc.domain {
if domain := Domain(named); domain != tc.domain {
t.Errorf("unexpected domain: got %q, expected %q", domain, tc.domain)
}
if name != tc.name {
t.Errorf("unexpected name: got %q, expected %q", name, tc.name)
if path := Path(named); path != tc.path {
t.Errorf("unexpected name: got %q, expected %q", path, tc.path)
}
})
}
Expand Down