...

Source file src/go.einride.tech/aip/resourcename/rangeparents_test.go

Documentation: go.einride.tech/aip/resourcename

     1  package resourcename
     2  
     3  import (
     4  	"testing"
     5  
     6  	"gotest.tools/v3/assert"
     7  )
     8  
     9  func TestRangeParents(t *testing.T) {
    10  	t.Parallel()
    11  	for _, tt := range []struct {
    12  		name     string
    13  		input    string
    14  		expected []string
    15  	}{
    16  		{
    17  			name:  "empty",
    18  			input: "",
    19  		},
    20  
    21  		{
    22  			name:  "singleton",
    23  			input: "foo",
    24  		},
    25  
    26  		{
    27  			name:  "single",
    28  			input: "foo/bar",
    29  			expected: []string{
    30  				"foo",
    31  			},
    32  		},
    33  
    34  		{
    35  			name:  "multiple",
    36  			input: "foo/bar/baz/123",
    37  			expected: []string{
    38  				"foo",
    39  				"foo/bar",
    40  				"foo/bar/baz",
    41  			},
    42  		},
    43  
    44  		{
    45  			name:  "full",
    46  			input: "//test.example.com/foo/bar/baz/123",
    47  			expected: []string{
    48  				"foo",
    49  				"foo/bar",
    50  				"foo/bar/baz",
    51  			},
    52  		},
    53  	} {
    54  		tt := tt
    55  		t.Run(tt.name, func(t *testing.T) {
    56  			t.Parallel()
    57  			var actual []string
    58  			RangeParents(tt.input, func(parent string) bool {
    59  				actual = append(actual, parent)
    60  				return true
    61  			})
    62  			assert.DeepEqual(t, tt.expected, actual)
    63  		})
    64  	}
    65  }
    66  

View as plain text