| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | package limayaml |
| 7 | |
| 8 | import ( |
| 9 | "testing" |
| 10 | |
| 11 | "gotest.tools/v3/assert" |
| 12 | ) |
| 13 | |
| 14 | func TestValidateMounts(t *testing.T) { |
| 15 | yBase := `images: [{"location": "/dummy"}]` |
| 16 | tests := []struct { |
| 17 | name string |
| 18 | mounts string |
| 19 | skipOnWindows bool |
| 20 | wantErr string |
| 21 | }{ |
| 22 | { |
| 23 | name: "Valid", |
| 24 | mounts: `mounts: [{location: "/foo", writable: false}, {location: "~/foo", writable: true}]`, |
| 25 | wantErr: "", |
| 26 | }, |
| 27 | { |
| 28 | name: "Invalid (relative)", |
| 29 | mounts: `mounts: [{location: ".", writable: false}]`, |
| 30 | wantErr: func() string { |
| 31 | return "must be an absolute path" |
| 32 | }(), |
| 33 | }, |
| 34 | } |
| 35 | |
| 36 | for _, tt := range tests { |
| 37 | t.Run(tt.name, func(t *testing.T) { |
| 38 | y, err := Load(t.Context(), []byte(yBase+"\n"+tt.mounts), "lima.yaml") |
| 39 | assert.NilError(t, err) |
| 40 | err = Validate(y, false) |
| 41 | if tt.wantErr != "" { |
| 42 | assert.ErrorContains(t, err, tt.wantErr) |
| 43 | } else { |
| 44 | assert.NilError(t, err) |
| 45 | } |
| 46 | }) |
| 47 | } |
| 48 | } |