github.com/containerd/nerdctl@v1.7.7/pkg/imgutil/imgutil_test.go (about)

     1  /*
     2     Copyright The containerd 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 imgutil
    18  
    19  import (
    20  	"testing"
    21  
    22  	"gotest.tools/v3/assert"
    23  )
    24  
    25  func TestParseRepoTag(t *testing.T) {
    26  	type testCase struct {
    27  		imgName string
    28  		repo    string
    29  		tag     string
    30  	}
    31  	testCases := []testCase{
    32  		{
    33  			imgName: "127.0.0.1:5000/foo/bar:baz",
    34  			repo:    "127.0.0.1:5000/foo/bar",
    35  			tag:     "baz",
    36  		},
    37  		{
    38  			imgName: "docker.io/library/alpine:latest",
    39  			repo:    "alpine",
    40  			tag:     "latest",
    41  		},
    42  		{
    43  			imgName: "docker.io/foo/bar:baz",
    44  			repo:    "foo/bar",
    45  			tag:     "baz",
    46  		},
    47  		{
    48  			// created by BuildKit
    49  			imgName: "overlayfs@sha256:da203733d47434b9e8b4d3f70e1c0c3ea59438353252fe600cb9eb1a1e808c4f",
    50  			repo:    "overlayfs",
    51  			tag:     "",
    52  		},
    53  	}
    54  	for _, tc := range testCases {
    55  		repo, tag := ParseRepoTag(tc.imgName)
    56  		assert.Equal(t, tc.repo, repo)
    57  		assert.Equal(t, tc.tag, tag)
    58  	}
    59  }