github.com/goravel/framework@v1.13.9/support/path/path_test.go (about) 1 package path 2 3 import ( 4 "path/filepath" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestApp(t *testing.T) { 11 tests := map[string]struct { 12 a []string 13 expected string 14 }{ 15 "no args": { 16 a: []string{}, 17 expected: "app", 18 }, 19 "single arg": { 20 a: []string{"config/goravel.go"}, 21 expected: filepath.Join("app", "config", "goravel.go"), 22 }, 23 "multi arg": { 24 a: []string{"config/goravel.go", "database/migrations"}, 25 expected: filepath.Join("app", "config", "goravel.go"), 26 }, 27 } 28 29 for name, test := range tests { 30 t.Run(name, func(t *testing.T) { 31 actual := App(test.a...) 32 33 assert.Equal(t, test.expected, actual) 34 }) 35 } 36 } 37 38 func TestBase(t *testing.T) { 39 tests := map[string]struct { 40 a []string 41 expected string 42 }{ 43 "no args": { 44 a: []string{}, 45 expected: "", 46 }, 47 "single arg": { 48 a: []string{"config/goravel.go"}, 49 expected: filepath.Join("config", "goravel.go"), 50 }, 51 "multi arg": { 52 a: []string{"config/goravel.go", "database/migrations"}, 53 expected: filepath.Join("config", "goravel.go"), 54 }, 55 } 56 57 for name, test := range tests { 58 t.Run(name, func(t *testing.T) { 59 actual := Base(test.a...) 60 61 assert.Equal(t, test.expected, actual) 62 }) 63 } 64 } 65 66 func TestConfig(t *testing.T) { 67 tests := map[string]struct { 68 a []string 69 expected string 70 }{ 71 "no args": { 72 a: []string{}, 73 expected: "config", 74 }, 75 "single arg": { 76 a: []string{"goravel.go"}, 77 expected: filepath.Join("config", "goravel.go"), 78 }, 79 "multi arg": { 80 a: []string{"goravel.go", "database/migrations"}, 81 expected: filepath.Join("config", "goravel.go"), 82 }, 83 } 84 85 for name, test := range tests { 86 t.Run(name, func(t *testing.T) { 87 actual := Config(test.a...) 88 89 assert.Equal(t, test.expected, actual) 90 }) 91 } 92 } 93 94 func TestDatabase(t *testing.T) { 95 tests := map[string]struct { 96 a []string 97 expected string 98 }{ 99 "no args": { 100 a: []string{}, 101 expected: "database", 102 }, 103 "single arg": { 104 a: []string{"migrations"}, 105 expected: filepath.Join("database", "migrations"), 106 }, 107 "multi arg": { 108 a: []string{"migrations", ".gitignore"}, 109 expected: filepath.Join("database", "migrations"), 110 }, 111 } 112 113 for name, test := range tests { 114 t.Run(name, func(t *testing.T) { 115 actual := Database(test.a...) 116 117 assert.Equal(t, test.expected, actual) 118 }) 119 } 120 } 121 122 func TestStorage(t *testing.T) { 123 tests := map[string]struct { 124 a []string 125 expected string 126 }{ 127 "no args": { 128 a: []string{}, 129 expected: "storage", 130 }, 131 "single arg": { 132 a: []string{"test"}, 133 expected: filepath.Join("storage", "test"), 134 }, 135 "multi arg": { 136 a: []string{"test", ".gitignore"}, 137 expected: filepath.Join("storage", "test"), 138 }, 139 } 140 141 for name, test := range tests { 142 t.Run(name, func(t *testing.T) { 143 actual := Storage(test.a...) 144 145 assert.Equal(t, test.expected, actual) 146 }) 147 } 148 } 149 150 func TestPublic(t *testing.T) { 151 tests := map[string]struct { 152 a []string 153 expected string 154 }{ 155 "no args": { 156 a: []string{}, 157 expected: "public", 158 }, 159 "single arg": { 160 a: []string{"test"}, 161 expected: filepath.Join("public", "test"), 162 }, 163 "multi arg": { 164 a: []string{"test", ".gitignore"}, 165 expected: filepath.Join("public", "test"), 166 }, 167 } 168 169 for name, test := range tests { 170 t.Run(name, func(t *testing.T) { 171 actual := Public(test.a...) 172 173 assert.Equal(t, test.expected, actual) 174 }) 175 } 176 }