github.com/telepresenceio/telepresence/v2@v2.20.0-pro.6.0.20240517030216-236ea954e789/pkg/client/docker/daemon_test.go (about)

     1  package docker
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/telepresenceio/telepresence/v2/pkg/ioutil"
     7  )
     8  
     9  func TestSafeContainerName(t *testing.T) {
    10  	tests := []struct {
    11  		name string
    12  		want string
    13  	}{
    14  		{
    15  			"@",
    16  			"a",
    17  		},
    18  		{
    19  			"@x",
    20  			"ax",
    21  		},
    22  		{
    23  			"x@",
    24  			"x_",
    25  		},
    26  		{
    27  			"x@y",
    28  			"x_y",
    29  		},
    30  		{
    31  			"x™y", // multibyte char
    32  			"x_y",
    33  		},
    34  		{
    35  			"x™", // multibyte char
    36  			"x_",
    37  		},
    38  		{
    39  			"_y",
    40  			"ay",
    41  		},
    42  		{
    43  			"_y_",
    44  			"ay_",
    45  		},
    46  		// TODO: Add test cases.
    47  	}
    48  	for _, tt := range tests {
    49  		t.Run(tt.name, func(t *testing.T) {
    50  			if got := ioutil.SafeName(tt.name); got != tt.want {
    51  				t.Errorf("SafeName() = %v, want %v", got, tt.want)
    52  			}
    53  		})
    54  	}
    55  }