github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/tests/storage_test.go (about) 1 package tests 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/taubyte/tau-cli/constants" 8 storagePrompts "github.com/taubyte/tau-cli/prompts/storage" 9 ) 10 11 func TestStorageAll(t *testing.T) { 12 runTests(t, createStorageMonkey(), true) 13 } 14 15 func createStorageMonkey() *testSpider { 16 // Define shared variables 17 command := "storage" 18 profileName := "test" 19 projectName := "test_project" 20 testName := "someStorage" 21 22 // Create a basic resource of name 23 basicNew := func(name string) []string { 24 return []string{ 25 "new", "-y", command, 26 "--name", name, 27 "--description", "some storage description", 28 "--tags", "tag1, tag2, tag3", 29 "--bucket", "Streaming", 30 "--ttl", "20s", 31 "--no-regex", 32 "--match", "test/v1", 33 "--public", 34 "--size", "10", 35 "--size-unit", "GB", 36 } 37 } 38 39 // The config that will be written 40 getConfigString := basicGetConfigString(profileName, projectName) 41 42 // Run before each test 43 beforeEach := func(tt testMonkey) [][]string { 44 tt.env[constants.CurrentProjectEnvVarName] = projectName 45 return nil 46 } 47 48 // Define test monkeys that will run in parallel 49 tests := []testMonkey{ 50 { 51 name: "Simple new", 52 args: []string{"query", command, testName}, 53 children: []testMonkey{ 54 { 55 name: "New basic", 56 args: []string{ 57 "new", "-y", command, 58 "--name", testName, 59 "--description", "some storage description", 60 "--tags", "tag1, tag2, tag3", 61 "-bucket", "Streaming", 62 "--ttl", "20s", 63 "--no-regex", 64 "--match", "test/v1", 65 "-public", 66 "-size", "10", 67 "-size-unit", "GB", 68 }, 69 wantOut: []string{command, testName, "Created"}, 70 }, 71 }, 72 }, 73 { 74 name: "Query new", 75 args: []string{"query", command, testName}, 76 wantOut: []string{ 77 testName, 78 "some storage description", 79 "tag1", "tag2", "tag3", 80 "Streaming", 81 "all", "10", "GB", 82 }, 83 dontWantOut: []string{"true"}, 84 children: []testMonkey{ 85 { 86 name: "New basic", 87 args: basicNew(testName), 88 wantOut: []string{command, testName, "Created"}, 89 }, 90 }, 91 }, 92 { 93 name: "Query edit", 94 args: []string{"query", command, testName}, 95 wantOut: []string{ 96 testName, 97 "some new storage description", 98 "tag543", "tag422", "tag341", 99 "Streaming", "all", "15", "KB", 100 }, 101 preRun: [][]string{ 102 basicNew(testName), 103 }, 104 children: []testMonkey{ 105 { 106 name: "Edit basic", 107 args: []string{"edit", "-y", command, "--name", testName, 108 "--description", "some new storage description", 109 "--tags", "tag543, tag422, tag341", 110 "--bucket", "Streaming", 111 "--ttl", "25s", 112 "--public", 113 "--no-regex", 114 "--size", "15", 115 "--size-unit", "KB", 116 "--match", "test/v1", 117 }, 118 wantOut: []string{command, testName, "Edited"}, 119 }, 120 }, 121 }, 122 { 123 name: "Query delete", 124 args: []string{"query", command, testName}, 125 exitCode: 1, 126 errOut: []string{fmt.Sprintf(storagePrompts.NotFound, testName)}, 127 preRun: [][]string{ 128 basicNew(testName), 129 }, 130 children: []testMonkey{ 131 { 132 name: "Delete basic", 133 args: []string{"delete", "-y", command, "--name", testName}, 134 wantOut: []string{command, testName, "Deleted"}, 135 }, 136 }, 137 }, 138 { 139 name: "Query list", 140 args: []string{"query", command, "--list"}, 141 wantOut: []string{ 142 "someStrg1", 143 "someStrg2", 144 // "someStrg3", deleted 145 "someStrg4", 146 "someStrg5", 147 }, 148 dontWantOut: []string{ 149 "someStrg3", 150 }, 151 preRun: [][]string{ 152 basicNew("someStrg1"), 153 basicNew("someStrg2"), 154 basicNew("someStrg3"), 155 {"delete", "-y", command, "--name", "someStrg3"}, 156 basicNew("someStrg4"), 157 basicNew("someStrg5"), 158 }, 159 }, 160 { 161 name: "New with selected application", 162 args: []string{"query", command, testName}, 163 wantOut: []string{ 164 testName, 165 "some storage description", 166 "tag1", "tag2", "tag3", 167 "Streaming", 168 "all", "10", "GB", 169 }, 170 dontWantOut: []string{"true"}, 171 preRun: [][]string{ 172 basicNew(testName), 173 }, 174 env: map[string]string{ 175 constants.CurrentApplicationEnvVarName: "someasdasdapp", 176 }, 177 }, 178 { 179 name: "Edit with selected application", 180 args: []string{"query", command, testName}, 181 wantOut: []string{ 182 testName, 183 "some new storage description", 184 "tag1", "tag2", "tag343", 185 "host", "15", "KB", 186 }, 187 preRun: [][]string{ 188 basicNew(testName), 189 }, 190 env: map[string]string{ 191 constants.CurrentApplicationEnvVarName: "someasdasdapp", 192 }, 193 children: []testMonkey{ 194 { 195 name: "Edit with selected application", 196 args: []string{"edit", "-y", command, "--name", testName, 197 "--description", "some new storage description", 198 "--tags", "tag1, tag2, tag343", 199 "--bucket", "Streaming", 200 "--ttl", "25s", 201 "--no-public", 202 "--no-regex", 203 "--match", "some/match", 204 "--size", "15", 205 "--size-unit", "KB", 206 }, 207 }, 208 }, 209 }, 210 { 211 name: "Delete with selected application", 212 args: []string{"query", command, testName}, 213 exitCode: 1, 214 errOut: []string{fmt.Sprintf(storagePrompts.NotFound, testName)}, 215 preRun: [][]string{ 216 basicNew(testName), 217 }, 218 env: map[string]string{ 219 constants.CurrentApplicationEnvVarName: "someasdasdapp", 220 }, 221 children: []testMonkey{ 222 { 223 name: "Delete with selected application", 224 args: []string{"delete", "-y", command, "--name", testName}, 225 }, 226 }, 227 }, 228 { 229 name: "Differencing New Streaming", 230 args: []string{"query", command, testName}, 231 wantOut: []string{ 232 testName, 233 "some storage description", 234 "tag1", "tag2", "tag3", 235 "Streaming", 236 "all", "10GB", 237 }, 238 dontWantOut: []string{"true"}, 239 preRun: [][]string{ 240 basicNew(testName), 241 }, 242 }, 243 { 244 name: "Differencing New Object", 245 args: []string{"query", command, testName}, 246 wantOut: []string{ 247 testName, 248 "some storage description", 249 "tag1", "tag2", "tag3", 250 "Object", "Versioning", 251 "all", "10", "GB", 252 }, 253 dontWantOut: []string{"TTL"}, 254 preRun: [][]string{ 255 {"new", "-y", command, "--name", testName, 256 "--description", "some storage description", 257 "--tags", "tag1, tag2, tag3", 258 "--bucket", "Object", 259 "--public", 260 "--versioning", 261 "--no-regex", 262 "--match", "some/match", 263 "--size", "10", 264 "--size-unit", "GB", 265 }, 266 }, 267 }, 268 { 269 name: "Differencing Edit Object to Streaming", 270 args: []string{"query", command, testName}, 271 wantOut: []string{ 272 testName, 273 "some new storage description", 274 "tag1", "tag2", "tag3", 275 "Streaming", "TTL", 276 "all", "10", "GB", 277 }, 278 dontWantOut: []string{"Versioning"}, 279 preRun: [][]string{ 280 {"new", "-y", command, "--name", testName, 281 "--description", "some new storage description", 282 "--tags", "tag1, tag2, tag3", 283 "--bucket", "Object", 284 "--no-public", 285 "--versioning", 286 "--no-regex", 287 "--match", "some/match", 288 "--size", "10", 289 "--size-unit", "GB", 290 }, 291 {"edit", "-y", command, "--name", testName, 292 "--description", "some new storage description", 293 "--tags", "tag1, tag2, tag3", 294 "--bucket", "Streaming", 295 "--ttl", "25s", 296 "--public", 297 "--no-regex", 298 "--match", "some/match", 299 "--size", "10", 300 "--size-unit", "GB", 301 }, 302 }, 303 }, 304 { 305 name: "Differencing Edit Streaming to Object", 306 args: []string{"query", command, testName}, 307 wantOut: []string{ 308 testName, 309 "some new storage description", 310 "tag1", "tag2", "tag3", 311 "Object", "Versioning", 312 "all", "10", "GB", 313 }, 314 dontWantOut: []string{"TTL"}, 315 preRun: [][]string{ 316 basicNew(testName), 317 {"edit", "-y", command, "--name", testName, 318 "--description", "some new storage description", 319 "--tags", "tag1, tag2, tag3", 320 "--bucket", "Object", 321 "--public", 322 "--versioning", 323 "--no-regex", 324 "--match", "some/match", 325 "--size", "10", 326 "--size-unit", "GB", 327 }, 328 }, 329 }, 330 } 331 return &testSpider{projectName, tests, beforeEach, getConfigString, "storage"} 332 333 }