github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/libraries/doltcore/dbfactory/aws_test.go (about) 1 // Copyright 2019 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package dbfactory 16 17 import ( 18 "testing" 19 20 "github.com/stretchr/testify/assert" 21 ) 22 23 func TestAWSPathValidation(t *testing.T) { 24 tests := []struct { 25 name string 26 path string 27 expectedPath string 28 expectErr bool 29 }{ 30 { 31 "empty path", 32 "", 33 "", 34 true, 35 }, 36 { 37 "basic", 38 "database", 39 "database", 40 false, 41 }, 42 { 43 "slash prefix", 44 "/database", 45 "database", 46 false, 47 }, 48 { 49 "slash suffix", 50 "database/", 51 "database", 52 false, 53 }, 54 { 55 "slash prefix and suffix", 56 "/database/", 57 "database", 58 false, 59 }, 60 { 61 "slash in the middle", 62 "/data/base/", 63 "", 64 true, 65 }, 66 } 67 68 for _, test := range tests { 69 t.Run(test.name, func(t *testing.T) { 70 actualPath, actualErr := validatePath(test.path) 71 72 assert.Equal(t, actualPath, test.expectedPath) 73 74 if test.expectErr { 75 assert.Error(t, actualErr, "Did not expect an error") 76 } else { 77 assert.NoError(t, actualErr, "Expected an error") 78 } 79 }) 80 } 81 }