github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/pkg/apis/identifiers_test.go (about)

     1  package apis_test
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  
     9  	"github.com/tilt-dev/tilt/pkg/apis"
    10  )
    11  
    12  func TestSanitizeName(t *testing.T) {
    13  	testCases := [][2]string{
    14  		{"abc123", "abc123"},
    15  		{"_def%456_", "_def_456_"},
    16  		{"$/./resource", "$_._resource"},
    17  	}
    18  
    19  	for _, tc := range testCases {
    20  		t.Run(tc[0], func(t *testing.T) {
    21  			assert.Equal(t, tc[1], apis.SanitizeName(tc[0]))
    22  		})
    23  	}
    24  
    25  	t.Run("Max Length Exceeded", func(t *testing.T) {
    26  		tooLong := strings.Repeat("abc123", 50)
    27  		expected := tooLong[:apis.MaxNameLength-9] + "-3c8e47c5"
    28  		assert.Equal(t, expected, apis.SanitizeName(tooLong))
    29  	})
    30  }