| 476 | } |
| 477 | |
| 478 | func TestMountOptSetBindCreateSrc(t *testing.T) { |
| 479 | tests := []struct { |
| 480 | value string |
| 481 | exp bool |
| 482 | expErr string |
| 483 | }{ |
| 484 | {value: "", exp: false}, |
| 485 | {value: "bind-create-src", exp: true}, |
| 486 | {value: "bind-create-src=", expErr: `invalid value for 'bind-create-src': value is empty`}, |
| 487 | {value: "bind-create-src= true", expErr: `invalid value for 'bind-create-src' in 'bind-create-src= true': value should not have whitespace`}, |
| 488 | {value: "bind-create-src=no", expErr: `invalid value for 'bind-create-src': invalid boolean value ("no"): must be one of "true", "1", "false", or "0" (default "true")`}, |
| 489 | {value: "bind-create-src=1", exp: true}, |
| 490 | {value: "bind-create-src=true", exp: true}, |
| 491 | {value: "bind-create-src=0", exp: false}, |
| 492 | {value: "bind-create-src=false", exp: false}, |
| 493 | } |
| 494 | |
| 495 | for _, tc := range tests { |
| 496 | name := tc.value |
| 497 | if name == "" { |
| 498 | name = "not set" |
| 499 | } |
| 500 | t.Run(name, func(t *testing.T) { |
| 501 | val := "type=bind,target=/foo,source=/foo" |
| 502 | if tc.value != "" { |
| 503 | val += "," + tc.value |
| 504 | } |
| 505 | var m MountOpt |
| 506 | err := m.Set(val) |
| 507 | if tc.expErr != "" { |
| 508 | assert.Error(t, err, tc.expErr) |
| 509 | return |
| 510 | } |
| 511 | assert.NilError(t, err) |
| 512 | if tc.value == "" { |
| 513 | assert.Check(t, is.Nil(m.values[0].BindOptions)) |
| 514 | } else { |
| 515 | assert.Check(t, m.values[0].BindOptions != nil) |
| 516 | assert.Check(t, is.Equal(m.values[0].BindOptions.CreateMountpoint, tc.exp)) |
| 517 | } |
| 518 | }) |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | func TestMountOptSetBindRecursive(t *testing.T) { |
| 523 | t.Run("enabled", func(t *testing.T) { |