code.vegaprotocol.io/vega@v0.79.0/paths/custom_test.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package paths_test 17 18 import ( 19 "path/filepath" 20 "testing" 21 22 vgtest "code.vegaprotocol.io/vega/libs/test" 23 "code.vegaprotocol.io/vega/paths" 24 25 "github.com/stretchr/testify/assert" 26 "github.com/stretchr/testify/require" 27 ) 28 29 func TestCustomPaths(t *testing.T) { 30 t.Run("Getting custom path for cache file succeeds", testGettingCustomPathForCacheFileSucceeds) 31 t.Run("Getting custom path for config file succeeds", testGettingCustomPathForConfigFileSucceeds) 32 t.Run("Getting custom path for data file succeeds", testGettingCustomPathForDataFileSucceeds) 33 t.Run("Getting custom path for state file succeeds", testGettingCustomPathForStateFileSucceeds) 34 t.Run("Getting custom path from struct for cache file succeeds", testGettingCustomPathFromStructForCacheFileSucceeds) 35 t.Run("Getting custom path from struct for config file succeeds", testGettingCustomPathFromStructForConfigFileSucceeds) 36 t.Run("Getting custom path from struct for data file succeeds", testGettingCustomPathFromStructForDataFileSucceeds) 37 t.Run("Getting custom path from struct for state file succeeds", testGettingCustomPathFromStructForStateFileSucceeds) 38 } 39 40 func testGettingCustomPathForCacheFileSucceeds(t *testing.T) { 41 home := t.TempDir() 42 path, err := paths.CreateCustomCachePathFor(home, "fake-file.empty") 43 require.NoError(t, err) 44 vgtest.AssertDirAccess(t, filepath.Dir(home)) 45 assert.Equal(t, filepath.Join(home, "cache", "fake-file.empty"), path) 46 } 47 48 func testGettingCustomPathForConfigFileSucceeds(t *testing.T) { 49 home := t.TempDir() 50 path, err := paths.CreateCustomConfigPathFor(home, "fake-file.empty") 51 require.NoError(t, err) 52 vgtest.AssertDirAccess(t, filepath.Dir(home)) 53 assert.Equal(t, filepath.Join(home, "config", "fake-file.empty"), path) 54 } 55 56 func testGettingCustomPathForDataFileSucceeds(t *testing.T) { 57 home := t.TempDir() 58 path, err := paths.CreateCustomDataPathFor(home, "fake-file.empty") 59 require.NoError(t, err) 60 vgtest.AssertDirAccess(t, filepath.Dir(home)) 61 assert.Equal(t, filepath.Join(home, "data", "fake-file.empty"), path) 62 } 63 64 func testGettingCustomPathForStateFileSucceeds(t *testing.T) { 65 home := t.TempDir() 66 path, err := paths.CreateCustomStatePathFor(home, "fake-file.empty") 67 require.NoError(t, err) 68 vgtest.AssertDirAccess(t, filepath.Dir(home)) 69 assert.Equal(t, filepath.Join(home, "state", "fake-file.empty"), path) 70 } 71 72 func testGettingCustomPathFromStructForCacheFileSucceeds(t *testing.T) { 73 home := t.TempDir() 74 customPaths := &paths.CustomPaths{CustomHome: home} 75 path, err := customPaths.CreateCachePathFor("fake-file.empty") 76 require.NoError(t, err) 77 vgtest.AssertDirAccess(t, filepath.Dir(home)) 78 assert.Equal(t, filepath.Join(home, "cache", "fake-file.empty"), path) 79 } 80 81 func testGettingCustomPathFromStructForConfigFileSucceeds(t *testing.T) { 82 home := t.TempDir() 83 customPaths := &paths.CustomPaths{CustomHome: home} 84 path, err := customPaths.CreateConfigPathFor("fake-file.empty") 85 require.NoError(t, err) 86 vgtest.AssertDirAccess(t, filepath.Dir(home)) 87 assert.Equal(t, filepath.Join(home, "config", "fake-file.empty"), path) 88 } 89 90 func testGettingCustomPathFromStructForDataFileSucceeds(t *testing.T) { 91 home := t.TempDir() 92 customPaths := &paths.CustomPaths{CustomHome: home} 93 path, err := customPaths.CreateDataPathFor("fake-file.empty") 94 require.NoError(t, err) 95 vgtest.AssertDirAccess(t, filepath.Dir(home)) 96 assert.Equal(t, filepath.Join(home, "data", "fake-file.empty"), path) 97 } 98 99 func testGettingCustomPathFromStructForStateFileSucceeds(t *testing.T) { 100 home := t.TempDir() 101 customPaths := &paths.CustomPaths{CustomHome: home} 102 path, err := customPaths.CreateStatePathFor("fake-file.empty") 103 require.NoError(t, err) 104 vgtest.AssertDirAccess(t, filepath.Dir(home)) 105 assert.Equal(t, filepath.Join(home, "state", "fake-file.empty"), path) 106 }