github.com/blend/go-sdk@v1.20220411.3/sanitize/path_uuids_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package sanitize
     9  
    10  import (
    11  	"testing"
    12  
    13  	"github.com/blend/go-sdk/assert"
    14  )
    15  
    16  func Test_PathUUIDs(t *testing.T) {
    17  	testCases := [...]struct {
    18  		Input    string
    19  		Expected string
    20  	}{
    21  		{Input: "", Expected: ""},
    22  		{Input: "/", Expected: "/"},
    23  		{Input: "/foo", Expected: "/foo"},
    24  		{Input: "/foo/", Expected: "/foo/"},
    25  		{Input: "//foo", Expected: "//foo"},
    26  		{Input: "//foo//", Expected: "//foo//"},
    27  		{Input: "foo", Expected: "foo"},
    28  		{Input: "foo/", Expected: "foo/"},
    29  		{Input: "foo//", Expected: "foo//"},
    30  
    31  		{Input: "/foo/ffbb4178-1ef1-11ec-9255-00155d4fd2f2", Expected: "/foo/?"},
    32  		{Input: "foo/ffbb4178-1ef1-11ec-9255-00155d4fd2f2", Expected: "foo/?"},
    33  		{Input: "/foo/ffbb41781ef111ec925500155d4fd2f2", Expected: "/foo/?"},
    34  		{Input: "foo/ffbb41781ef111ec925500155d4fd2f2", Expected: "foo/?"},
    35  
    36  		{Input: "/foo/ffbb417", Expected: "/foo/ffbb417"},
    37  		{Input: "foo/ffbb417", Expected: "foo/ffbb417"},
    38  		{Input: "/foo/ffbb417/", Expected: "/foo/ffbb417/"},
    39  		{Input: "foo/ffbb417/", Expected: "foo/ffbb417/"},
    40  
    41  		{Input: "/foo/ffbb4178-1ef1-11ec-9255-00155d4fd2f2/", Expected: "/foo/?/"},
    42  		{Input: "foo/ffbb4178-1ef1-11ec-9255-00155d4fd2f2/", Expected: "foo/?/"},
    43  		{Input: "/foo/ffbb41781ef111ec925500155d4fd2f2/", Expected: "/foo/?/"},
    44  		{Input: "foo/ffbb41781ef111ec925500155d4fd2f2/", Expected: "foo/?/"},
    45  
    46  		{Input: "/foo/ffbb4178-1ef1-11ec-9255-00155d4fd2f2/bar", Expected: "/foo/?/bar"},
    47  		{Input: "foo/ffbb4178-1ef1-11ec-9255-00155d4fd2f2/bar", Expected: "foo/?/bar"},
    48  		{Input: "/foo/ffbb4178-1ef1-11ec-9255-00155d4fd2f2/bar/0db8cb24-1ef2-11ec-bc9c-00155d4fd2f2", Expected: "/foo/?/bar/?"},
    49  		{Input: "foo/ffbb4178-1ef1-11ec-9255-00155d4fd2f2/bar/0db8cb24-1ef2-11ec-bc9c-00155d4fd2f2", Expected: "foo/?/bar/?"},
    50  		{Input: "/foo/ffbb4178-1ef1-11ec-9255-00155d4fd2f2/bar/0db8cb24-1ef2-11ec-bc9c-00155d4fd2f2/", Expected: "/foo/?/bar/?/"},
    51  		{Input: "foo/ffbb4178-1ef1-11ec-9255-00155d4fd2f2/bar/0db8cb24-1ef2-11ec-bc9c-00155d4fd2f2/", Expected: "foo/?/bar/?/"},
    52  		{Input: "/foo/ffbb4178-1ef1-11ec-9255-00155d4fd2f2/bar/0db8cb24-1ef2-11ec-bc9c-00155d4fd2f2/baz", Expected: "/foo/?/bar/?/baz"},
    53  		{Input: "foo/ffbb4178-1ef1-11ec-9255-00155d4fd2f2/bar/0db8cb24-1ef2-11ec-bc9c-00155d4fd2f2/baz", Expected: "foo/?/bar/?/baz"},
    54  	}
    55  
    56  	for _, tc := range testCases {
    57  		t.Run(tc.Input, func(t2 *testing.T) {
    58  			its := assert.New(t2)
    59  			its.Equal(tc.Expected, PathUUIDs(tc.Input))
    60  		})
    61  	}
    62  }