| 179 | } |
| 180 | |
| 181 | func TestMountOptReadOnly(t *testing.T) { |
| 182 | tests := []struct { |
| 183 | value string |
| 184 | exp bool |
| 185 | expErr string |
| 186 | }{ |
| 187 | {value: "", exp: false}, |
| 188 | {value: "readonly", exp: true}, |
| 189 | {value: "readonly=", expErr: `invalid value for 'readonly': value is empty`}, |
| 190 | {value: "readonly= true", expErr: `invalid value for 'readonly' in 'readonly= true': value should not have whitespace`}, |
| 191 | {value: "readonly=no", expErr: `invalid value for 'readonly': invalid boolean value ("no"): must be one of "true", "1", "false", or "0" (default "true")`}, |
| 192 | {value: "readonly=1", exp: true}, |
| 193 | {value: "readonly=true", exp: true}, |
| 194 | {value: "readonly=0", exp: false}, |
| 195 | {value: "readonly=false", exp: false}, |
| 196 | {value: "ro", exp: true}, |
| 197 | {value: "ro=1", exp: true}, |
| 198 | {value: "ro=true", exp: true}, |
| 199 | {value: "ro=0", exp: false}, |
| 200 | {value: "ro=false", exp: false}, |
| 201 | } |
| 202 | |
| 203 | for _, tc := range tests { |
| 204 | name := tc.value |
| 205 | if name == "" { |
| 206 | name = "not set" |
| 207 | } |
| 208 | t.Run(name, func(t *testing.T) { |
| 209 | val := "type=bind,target=/foo,source=/foo" |
| 210 | if tc.value != "" { |
| 211 | val += "," + tc.value |
| 212 | } |
| 213 | var m MountOpt |
| 214 | err := m.Set(val) |
| 215 | if tc.expErr != "" { |
| 216 | assert.Error(t, err, tc.expErr) |
| 217 | return |
| 218 | } |
| 219 | assert.NilError(t, err) |
| 220 | assert.Check(t, is.Equal(m.values[0].ReadOnly, tc.exp)) |
| 221 | }) |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | func TestMountOptVolumeNoCopy(t *testing.T) { |
| 226 | tests := []struct { |