github.com/demonoid81/containerd@v1.3.4/remotes/docker/handler_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 docker
    18  
    19  import (
    20  	"reflect"
    21  	"testing"
    22  )
    23  
    24  func TestAppendDistributionLabel(t *testing.T) {
    25  	for _, tc := range []struct {
    26  		originLabel string
    27  		repo        string
    28  		expected    string
    29  	}{
    30  		{
    31  			originLabel: "",
    32  			repo:        "",
    33  			expected:    "",
    34  		},
    35  		{
    36  			originLabel: "",
    37  			repo:        "library/busybox",
    38  			expected:    "library/busybox",
    39  		},
    40  		{
    41  			originLabel: "library/busybox",
    42  			repo:        "library/busybox",
    43  			expected:    "library/busybox",
    44  		},
    45  		// remove the duplicate one in origin
    46  		{
    47  			originLabel: "library/busybox,library/redis,library/busybox",
    48  			repo:        "library/alpine",
    49  			expected:    "library/alpine,library/busybox,library/redis",
    50  		},
    51  		// remove the empty repo
    52  		{
    53  			originLabel: "library/busybox,library/redis,library/busybox",
    54  			repo:        "",
    55  			expected:    "library/busybox,library/redis",
    56  		},
    57  		{
    58  			originLabel: "library/busybox,library/redis,library/busybox",
    59  			repo:        "library/redis",
    60  			expected:    "library/busybox,library/redis",
    61  		},
    62  	} {
    63  		if got := appendDistributionSourceLabel(tc.originLabel, tc.repo); !reflect.DeepEqual(got, tc.expected) {
    64  			t.Fatalf("expected %v, but got %v", tc.expected, got)
    65  		}
    66  	}
    67  }