github.com/apptainer/singularity@v3.1.1+incompatible/internal/pkg/util/uri/uri_test.go (about)

     1  // Copyright (c) 2018, Sylabs Inc. All rights reserved.
     2  // This software is licensed under a 3-clause BSD license. Please consult the
     3  // LICENSE.md file distributed with the sources of this project regarding your
     4  // rights to use or distribute this software.
     5  
     6  package uri
     7  
     8  import "testing"
     9  
    10  func Test_GetName(t *testing.T) {
    11  	tests := []struct {
    12  		name     string
    13  		uri      string
    14  		expected string
    15  	}{
    16  		{"docker basic", "docker://ubuntu", "ubuntu_latest.sif"},
    17  		{"docker scoped", "docker://user/image", "image_latest.sif"},
    18  		{"dave's magical lolcow", "docker://godlovedc/lolcow", "lolcow_latest.sif"},
    19  		{"docker w/ tags", "docker://godlovedc/lolcow:3.7", "lolcow_3.7.sif"},
    20  	}
    21  
    22  	for _, tt := range tests {
    23  		t.Run(tt.name, func(t *testing.T) {
    24  			if n := GetName(tt.uri); n != tt.expected {
    25  				t.Errorf("incorrectly parsed name as \"%v\" (expected \"%s\")", n, tt.expected)
    26  			}
    27  		})
    28  	}
    29  }
    30  
    31  func Test_Split(t *testing.T) {
    32  	tests := []struct {
    33  		name      string
    34  		uri       string
    35  		transport string
    36  		ref       string
    37  	}{
    38  		{"docker basic", "docker://ubuntu", "docker", "//ubuntu"},
    39  		{"docker scoped", "docker://user/image", "docker", "//user/image"},
    40  		{"dave's magical lolcow", "docker://godlovedc/lolcow", "docker", "//godlovedc/lolcow"},
    41  		{"docker with tags", "docker://godlovedc/lolcow:latest", "docker", "//godlovedc/lolcow:latest"},
    42  		{"library basic", "library://image", "library", "//image"},
    43  		{"library scoped", "library://collection/image", "library", "//collection/image"},
    44  		{"without transport", "ubuntu", "", "ubuntu"},
    45  		{"without transport with colon", "ubuntu:18.04.img", "", "ubuntu:18.04.img"},
    46  	}
    47  
    48  	for _, tt := range tests {
    49  		t.Run(tt.name, func(t *testing.T) {
    50  			if tr, r := Split(tt.uri); tr != tt.transport || r != tt.ref {
    51  				t.Errorf("incorrectly parsed uri as %s : %s (expected %s : %s)", tr, r, tt.transport, tt.ref)
    52  			}
    53  		})
    54  	}
    55  }