github.com/treeverse/lakefs@v1.24.1-0.20240520134607-95648127bfb0/pkg/block/local/adapter_test.go (about) 1 package local_test 2 3 import ( 4 "path" 5 "regexp" 6 "testing" 7 8 "github.com/stretchr/testify/require" 9 "github.com/treeverse/lakefs/pkg/block" 10 "github.com/treeverse/lakefs/pkg/block/blocktest" 11 "github.com/treeverse/lakefs/pkg/block/local" 12 ) 13 14 const testStorageNamespace = "local://test" 15 16 func TestLocalAdapter(t *testing.T) { 17 tmpDir := t.TempDir() 18 localPath := path.Join(tmpDir, "lakefs") 19 externalPath := block.BlockstoreTypeLocal + "://" + path.Join(tmpDir, "lakefs", "external") 20 adapter, err := local.NewAdapter(localPath, local.WithRemoveEmptyDir(false)) 21 if err != nil { 22 t.Fatal("Failed to create new adapter", err) 23 } 24 blocktest.AdapterTest(t, adapter, testStorageNamespace, externalPath) 25 } 26 27 func TestAdapterNamespace(t *testing.T) { 28 tmpDir := t.TempDir() 29 localPath := path.Join(tmpDir, "lakefs") 30 adapter, err := local.NewAdapter(localPath, local.WithRemoveEmptyDir(false)) 31 require.NoError(t, err, "create new adapter") 32 expr, err := regexp.Compile(adapter.GetStorageNamespaceInfo().ValidityRegex) 33 require.NoError(t, err) 34 35 tests := []struct { 36 Name string 37 Namespace string 38 Success bool 39 }{ 40 { 41 Name: "valid_path", 42 Namespace: "local://test/path/to/repo1", 43 Success: true, 44 }, 45 { 46 Name: "invalid_path", 47 Namespace: "~/test/path/to/repo1", 48 Success: false, 49 }, 50 { 51 Name: "s3", 52 Namespace: "s3://test/adls/core/windows/net", 53 Success: false, 54 }, 55 { 56 Name: "invalid_string", 57 Namespace: "this is a bad string", 58 Success: false, 59 }, 60 } 61 for _, tt := range tests { 62 t.Run(tt.Name, func(t *testing.T) { 63 require.Equal(t, tt.Success, expr.MatchString(tt.Namespace)) 64 }) 65 } 66 }