code.vegaprotocol.io/vega@v0.79.0/paths/paths_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 vgrand "code.vegaprotocol.io/vega/libs/rand" 23 "code.vegaprotocol.io/vega/paths" 24 25 "github.com/stretchr/testify/assert" 26 ) 27 28 func TestCachePaths(t *testing.T) { 29 t.Run("Joining cache path as CachePath succeeds", testCachePathsJoiningCachePathAsCachePathSucceeds) 30 t.Run("Joining cache path as string succeeds", testCachePathsJoiningCachePathAsStringSucceeds) 31 } 32 33 func testCachePathsJoiningCachePathAsCachePathSucceeds(t *testing.T) { 34 // given 35 rootCachePath := paths.DataNodeCacheHome 36 pathElem1 := vgrand.RandomStr(5) 37 pathElem2 := vgrand.RandomStr(5) 38 39 // when 40 builtPath := paths.JoinCachePath(rootCachePath, pathElem1, pathElem2) 41 42 // then 43 assert.Equal(t, paths.CachePath(filepath.Join("data-node", pathElem1, pathElem2)), builtPath) 44 } 45 46 func testCachePathsJoiningCachePathAsStringSucceeds(t *testing.T) { 47 // given 48 rootCachePath := paths.DataNodeCacheHome 49 pathElem1 := vgrand.RandomStr(5) 50 pathElem2 := vgrand.RandomStr(5) 51 52 // when 53 builtPath := paths.JoinCachePath(rootCachePath, pathElem1, pathElem2) 54 55 // then 56 assert.Equal(t, paths.CachePath(filepath.Join("data-node", pathElem1, pathElem2)), builtPath) 57 } 58 59 func TestConfigPaths(t *testing.T) { 60 t.Run("Joining config path as ConfigPath succeeds", testConfigPathsJoiningConfigPathAsConfigPathSucceeds) 61 t.Run("Joining config path as string succeeds", testConfigPathsJoiningConfigPathAsStringSucceeds) 62 } 63 64 func testConfigPathsJoiningConfigPathAsConfigPathSucceeds(t *testing.T) { 65 // given 66 rootConfigPath := paths.NodeConfigHome 67 pathElem1 := vgrand.RandomStr(5) 68 pathElem2 := vgrand.RandomStr(5) 69 70 // when 71 builtPath := paths.JoinConfigPath(rootConfigPath, pathElem1, pathElem2) 72 73 // then 74 assert.Equal(t, paths.ConfigPath(filepath.Join("node", pathElem1, pathElem2)), builtPath) 75 } 76 77 func testConfigPathsJoiningConfigPathAsStringSucceeds(t *testing.T) { 78 // given 79 rootConfigPath := paths.NodeConfigHome 80 pathElem1 := vgrand.RandomStr(5) 81 pathElem2 := vgrand.RandomStr(5) 82 83 // when 84 builtPath := paths.JoinConfigPath(rootConfigPath, pathElem1, pathElem2) 85 86 // then 87 assert.Equal(t, paths.ConfigPath(filepath.Join("node", pathElem1, pathElem2)), builtPath) 88 } 89 90 func TestDataPaths(t *testing.T) { 91 t.Run("Joining data path as DataPath succeeds", testDataPathsJoiningDataPathAsDataPathSucceeds) 92 t.Run("Joining data path as string succeeds", testDataPathsJoiningDataPathAsStringSucceeds) 93 } 94 95 func testDataPathsJoiningDataPathAsDataPathSucceeds(t *testing.T) { 96 // given 97 rootDataPath := paths.NodeDataHome 98 pathElem1 := vgrand.RandomStr(5) 99 pathElem2 := vgrand.RandomStr(5) 100 101 // when 102 builtPath := paths.JoinDataPath(rootDataPath, pathElem1, pathElem2) 103 104 // then 105 assert.Equal(t, paths.DataPath(filepath.Join("node", pathElem1, pathElem2)), builtPath) 106 } 107 108 func testDataPathsJoiningDataPathAsStringSucceeds(t *testing.T) { 109 // given 110 rootDataPath := paths.NodeDataHome 111 pathElem1 := vgrand.RandomStr(5) 112 pathElem2 := vgrand.RandomStr(5) 113 114 // when 115 builtPath := paths.JoinDataPath(rootDataPath, pathElem1, pathElem2) 116 117 // then 118 assert.Equal(t, paths.DataPath(filepath.Join("node", pathElem1, pathElem2)), builtPath) 119 } 120 121 func TestStatePaths(t *testing.T) { 122 t.Run("Joining state path as StatePath succeeds", testStatePathsJoiningStatePathAsStatePathSucceeds) 123 t.Run("Joining state path as string succeeds", testStatePathsJoiningStatePathAsStringSucceeds) 124 } 125 126 func testStatePathsJoiningStatePathAsStatePathSucceeds(t *testing.T) { 127 // given 128 rootStatePath := paths.NodeStateHome 129 pathElem1 := vgrand.RandomStr(5) 130 pathElem2 := vgrand.RandomStr(5) 131 132 // when 133 builtPath := paths.JoinStatePath(rootStatePath, pathElem1, pathElem2) 134 135 // then 136 assert.Equal(t, paths.StatePath(filepath.Join("node", pathElem1, pathElem2)), builtPath) 137 } 138 139 func testStatePathsJoiningStatePathAsStringSucceeds(t *testing.T) { 140 // given 141 rootStatePath := paths.NodeStateHome 142 pathElem1 := vgrand.RandomStr(5) 143 pathElem2 := vgrand.RandomStr(5) 144 145 // when 146 builtPath := paths.JoinStatePath(rootStatePath, pathElem1, pathElem2) 147 148 // then 149 assert.Equal(t, paths.StatePath(filepath.Join("node", pathElem1, pathElem2)), builtPath) 150 }