github.com/demonoid81/containerd@v1.3.4/remotes/docker/registry_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 "testing"
    20  
    21  func TestHasCapability(t *testing.T) {
    22  	var (
    23  		pull = HostCapabilityPull
    24  		rslv = HostCapabilityResolve
    25  		push = HostCapabilityPush
    26  		all  = pull | rslv | push
    27  	)
    28  	for i, tc := range []struct {
    29  		c HostCapabilities
    30  		t HostCapabilities
    31  		e bool
    32  	}{
    33  		{all, pull, true},
    34  		{all, pull | rslv, true},
    35  		{all, pull | push, true},
    36  		{all, all, true},
    37  		{pull, all, false},
    38  		{pull, push, false},
    39  		{rslv, pull, false},
    40  		{pull | rslv, push, false},
    41  		{pull | rslv, rslv, true},
    42  	} {
    43  		if a := tc.c.Has(tc.t); a != tc.e {
    44  			t.Fatalf("%d: failed, expected %t, got %t", i, tc.e, a)
    45  		}
    46  	}
    47  }
    48  
    49  func TestMatchLocalhost(t *testing.T) {
    50  	for _, tc := range []struct {
    51  		host  string
    52  		match bool
    53  	}{
    54  		{"", false},
    55  		{"127.1.1.1", false},
    56  		{"127.0.0.1", true},
    57  		{"127.0.0.1:5000", true},
    58  		{"registry.org", false},
    59  		{"localhost", true},
    60  		{"localhost:5000", true},
    61  		{"[127:0:0:1]", false},
    62  		{"[::1]", true},
    63  		{"[::1]:5000", true},
    64  		{"::1", true},
    65  	} {
    66  		actual, _ := MatchLocalhost(tc.host)
    67  		if actual != tc.match {
    68  			if tc.match {
    69  				t.Logf("Expected match for %s", tc.host)
    70  			} else {
    71  				t.Logf("Unexpected match for %s", tc.host)
    72  			}
    73  			t.Fail()
    74  		}
    75  	}
    76  }