github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/schemadsl/compiler/translator_test.go (about) 1 package compiler 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 ) 8 9 func TestPrefixedPath(t *testing.T) { 10 fooPrefix := "foo" 11 barPrefix := "bar" 12 noPrefix := "" 13 14 testCases := []struct { 15 input string 16 prefix *string 17 expectedError bool 18 expected string 19 }{ 20 {"bar", &fooPrefix, false, "foo/bar"}, 21 {"bar", &barPrefix, false, "bar/bar"}, 22 {"bar", &noPrefix, false, "bar"}, 23 {"foo/bar", &fooPrefix, false, "foo/bar"}, 24 {"foo/bar", &barPrefix, false, "foo/bar"}, 25 {"foo/bar", &noPrefix, false, "foo/bar"}, 26 {"bar", nil, true, ""}, 27 } 28 29 for _, tc := range testCases { 30 t.Run(tc.input, func(t *testing.T) { 31 require := require.New(t) 32 33 tctx := translationContext{ 34 objectTypePrefix: tc.prefix, 35 } 36 output, err := tctx.prefixedPath(tc.input) 37 if tc.expectedError { 38 require.Error(err) 39 } else { 40 require.NoError(err) 41 require.Equal(tc.expected, output) 42 } 43 }) 44 } 45 }