TestValidateMountStringFormat tests the shared mount format validation primitive.
(t *testing.T)
| 344 | |
| 345 | // TestValidateMountStringFormat tests the shared mount format validation primitive. |
| 346 | func TestValidateMountStringFormat(t *testing.T) { |
| 347 | tests := []struct { |
| 348 | name string |
| 349 | mount string |
| 350 | wantErr bool |
| 351 | wantSrc string |
| 352 | wantDest string |
| 353 | wantMode string |
| 354 | allEmpty bool // true when format error (all three return values are empty) |
| 355 | }{ |
| 356 | { |
| 357 | name: "valid ro mount", |
| 358 | mount: "/host/data:/data:ro", |
| 359 | wantSrc: "/host/data", |
| 360 | wantDest: "/data", |
| 361 | wantMode: "ro", |
| 362 | }, |
| 363 | { |
| 364 | name: "valid rw mount", |
| 365 | mount: "/host/data:/data:rw", |
| 366 | wantSrc: "/host/data", |
| 367 | wantDest: "/data", |
| 368 | wantMode: "rw", |
| 369 | }, |
| 370 | { |
| 371 | name: "too few parts — format error, all values empty", |
| 372 | mount: "/host/path:/container/path", |
| 373 | wantErr: true, |
| 374 | allEmpty: true, |
| 375 | }, |
| 376 | { |
| 377 | name: "too many parts — format error, all values empty", |
| 378 | mount: "/host/path:/container/path:ro:extra", |
| 379 | wantErr: true, |
| 380 | allEmpty: true, |
| 381 | }, |
| 382 | { |
| 383 | name: "invalid mode — source and dest returned, mode returned", |
| 384 | mount: "/host/path:/container/path:xyz", |
| 385 | wantErr: true, |
| 386 | wantSrc: "/host/path", |
| 387 | wantDest: "/container/path", |
| 388 | wantMode: "xyz", |
| 389 | }, |
| 390 | { |
| 391 | name: "empty mode — source and dest returned, mode empty string", |
| 392 | mount: "/host/path:/container/path:", |
| 393 | wantErr: true, |
| 394 | wantSrc: "/host/path", |
| 395 | wantDest: "/container/path", |
| 396 | wantMode: "", |
| 397 | }, |
| 398 | } |
| 399 | |
| 400 | for _, tt := range tests { |
| 401 | t.Run(tt.name, func(t *testing.T) { |
| 402 | src, dest, mode, err := validateMountStringFormat(tt.mount) |
| 403 |
nothing calls this directly
no test coverage detected