Skip to content

Commit

Permalink
Merge pull request #5 from thaJeztah/rm_deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
milosgajdos authored Sep 1, 2023
2 parents 49c2849 + 4894124 commit a3fb784
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 51 deletions.
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

0 comments on commit a3fb784

Please sign in to comment.