github.com/qsis/helm@v3.0.0-beta.3+incompatible/internal/experimental/registry/reference_test.go (about)

     1  /*
     2  Copyright The Helm 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 registry
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/stretchr/testify/assert"
    23  )
    24  
    25  func TestParseReference(t *testing.T) {
    26  	is := assert.New(t)
    27  
    28  	// bad refs
    29  	s := ""
    30  	_, err := ParseReference(s)
    31  	is.Error(err, "empty ref")
    32  
    33  	s = "my:bad:ref"
    34  	_, err = ParseReference(s)
    35  	is.Error(err, "ref contains too many colons (2)")
    36  
    37  	s = "my:really:bad:ref"
    38  	_, err = ParseReference(s)
    39  	is.Error(err, "ref contains too many colons (3)")
    40  
    41  	// good refs
    42  	s = "mychart"
    43  	ref, err := ParseReference(s)
    44  	is.NoError(err)
    45  	is.Equal("mychart", ref.Repo)
    46  	is.Equal("", ref.Tag)
    47  	is.Equal("mychart", ref.FullName())
    48  
    49  	s = "mychart:1.5.0"
    50  	ref, err = ParseReference(s)
    51  	is.NoError(err)
    52  	is.Equal("mychart", ref.Repo)
    53  	is.Equal("1.5.0", ref.Tag)
    54  	is.Equal("mychart:1.5.0", ref.FullName())
    55  
    56  	s = "myrepo/mychart"
    57  	ref, err = ParseReference(s)
    58  	is.NoError(err)
    59  	is.Equal("myrepo/mychart", ref.Repo)
    60  	is.Equal("", ref.Tag)
    61  	is.Equal("myrepo/mychart", ref.FullName())
    62  
    63  	s = "myrepo/mychart:1.5.0"
    64  	ref, err = ParseReference(s)
    65  	is.NoError(err)
    66  	is.Equal("myrepo/mychart", ref.Repo)
    67  	is.Equal("1.5.0", ref.Tag)
    68  	is.Equal("myrepo/mychart:1.5.0", ref.FullName())
    69  
    70  	s = "mychart:5001:1.5.0"
    71  	ref, err = ParseReference(s)
    72  	is.NoError(err)
    73  	is.Equal("mychart:5001", ref.Repo)
    74  	is.Equal("1.5.0", ref.Tag)
    75  	is.Equal("mychart:5001:1.5.0", ref.FullName())
    76  
    77  	s = "myrepo:5001/mychart:1.5.0"
    78  	ref, err = ParseReference(s)
    79  	is.NoError(err)
    80  	is.Equal("myrepo:5001/mychart", ref.Repo)
    81  	is.Equal("1.5.0", ref.Tag)
    82  	is.Equal("myrepo:5001/mychart:1.5.0", ref.FullName())
    83  
    84  	s = "localhost:5000/mychart:latest"
    85  	ref, err = ParseReference(s)
    86  	is.NoError(err)
    87  	is.Equal("localhost:5000/mychart", ref.Repo)
    88  	is.Equal("latest", ref.Tag)
    89  	is.Equal("localhost:5000/mychart:latest", ref.FullName())
    90  
    91  	s = "my.host.com/my/nested/repo:1.2.3"
    92  	ref, err = ParseReference(s)
    93  	is.NoError(err)
    94  	is.Equal("my.host.com/my/nested/repo", ref.Repo)
    95  	is.Equal("1.2.3", ref.Tag)
    96  	is.Equal("my.host.com/my/nested/repo:1.2.3", ref.FullName())
    97  
    98  	s = "localhost:5000/x/y/z"
    99  	ref, err = ParseReference(s)
   100  	is.NoError(err)
   101  	is.Equal("localhost:5000/x/y/z", ref.Repo)
   102  	is.Equal("", ref.Tag)
   103  	is.Equal("localhost:5000/x/y/z", ref.FullName())
   104  
   105  	s = "localhost:5000/x/y/z:123"
   106  	ref, err = ParseReference(s)
   107  	is.NoError(err)
   108  	is.Equal("localhost:5000/x/y/z", ref.Repo)
   109  	is.Equal("123", ref.Tag)
   110  	is.Equal("localhost:5000/x/y/z:123", ref.FullName())
   111  
   112  	s = "localhost:5000/x/y/z:123:x"
   113  	_, err = ParseReference(s)
   114  	is.Error(err, "ref contains too many colons (3)")
   115  
   116  	s = "localhost:5000/x/y/z:123:x:y"
   117  	_, err = ParseReference(s)
   118  	is.Error(err, "ref contains too many colons (4)")
   119  }