github.com/estesp/manifest-tool@v1.0.3/docker/inspect_test.go (about)

     1  package docker
     2  
     3  import "testing"
     4  
     5  func TestSplitHostname(t *testing.T) {
     6  	var crcthostnames = []struct {
     7  		a, b, c string
     8  	}{
     9  		{"localhost:5000/hello-world", "localhost:5000", "hello-world"},
    10  		{"myregistrydomain:5000/java", "myregistrydomain:5000", "java"},
    11  		{"docker.io/busybox", "docker.io", "library/busybox"},
    12  	}
    13  	var wrnghostnames = []struct {
    14  		d, e, f string
    15  	}{
    16  		{"localhost:5000,hello-world", "localhost:5000", "hello-world"},
    17  		{"myregistrydomain:5000&java", "myregistrydomain:5000", "java"},
    18  		{"docker.io%busybox", "docker.io", "busybox"},
    19  	}
    20  
    21  	for _, i := range crcthostnames {
    22  		res1, res2 := splitHostname(i.a)
    23  		if res1 != i.b || res2 != i.c {
    24  			t.Errorf("%s should produce equals of: %q %q or %q %q", i.a, res1, i.b, res2, i.c)
    25  		}
    26  	}
    27  
    28  	for _, j := range wrnghostnames {
    29  		res1, res2 := splitHostname(j.d)
    30  		if res1 == j.e && res2 == j.f {
    31  			t.Errorf("%s should not produce equals of: %q %q and %q %q", j.d, res1, j.e, res2, j.f)
    32  		}
    33  	}
    34  }
    35  
    36  func TestValidateName(t *testing.T) {
    37  	var crctnames = []struct {
    38  		a string
    39  	}{
    40  		{"localhost:5000/hello-world"},
    41  		{"myregistrydomain:5000/java"},
    42  		{"docker.io/busybox"},
    43  	}
    44  	var wrngnames = []struct {
    45  		b string
    46  	}{
    47  		{"localhost:5000,hello-world"},
    48  		{"myregistrydomain:5000&java"},
    49  		{"docker.io@busybox"},
    50  	}
    51  
    52  	for _, i := range crctnames {
    53  		res := validateName(i.a)
    54  		if res != nil {
    55  			t.Errorf("%s is an invalid name", i.a)
    56  		}
    57  	}
    58  	for _, j := range wrngnames {
    59  		res := validateName(j.b)
    60  		if res == nil {
    61  			t.Errorf("%s is an invalid name", j.b)
    62  		}
    63  	}
    64  }