File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import (
12
12
"strings"
13
13
"unicode"
14
14
15
+ "github.com/containerd/containerd/identifiers"
15
16
"github.com/coreos/go-semver/semver"
16
17
"github.com/docker/go-units"
17
18
"github.com/lima-vm/lima/pkg/localpathutil"
@@ -136,6 +137,12 @@ func Validate(y *LimaYAML, warn bool) error {
136
137
return fmt .Errorf ("field `memory` has an invalid value: %w" , err )
137
138
}
138
139
140
+ for i , disk := range y .AdditionalDisks {
141
+ if err := identifiers .Validate (disk .Name ); err != nil {
142
+ return fmt .Errorf ("field `additionalDisks[%d].name is invalid`: %w" , i , err )
143
+ }
144
+ }
145
+
139
146
for i , f := range y .Mounts {
140
147
if ! filepath .IsAbs (f .Location ) && ! strings .HasPrefix (f .Location , "~" ) {
141
148
return fmt .Errorf ("field `mounts[%d].location` must be an absolute path, got %q" ,
Original file line number Diff line number Diff line change @@ -48,6 +48,31 @@ func TestValidateProbes(t *testing.T) {
48
48
assert .Error (t , err , "field `probe[0].script` must start with a '#!' line" )
49
49
}
50
50
51
+ func TestValidateAdditionalDisks (t * testing.T ) {
52
+ images := `images: [{"location": "/"}]`
53
+
54
+ validDisks := `
55
+ additionalDisks:
56
+ - name: "disk1"
57
+ - name: "disk2"
58
+ `
59
+ y , err := Load ([]byte (validDisks + "\n " + images ), "lima.yaml" )
60
+ assert .NilError (t , err )
61
+
62
+ err = Validate (y , false )
63
+ assert .NilError (t , err )
64
+
65
+ invalidDisks := `
66
+ additionalDisks:
67
+ - name: ""
68
+ `
69
+ y , err = Load ([]byte (invalidDisks + "\n " + images ), "lima.yaml" )
70
+ assert .NilError (t , err )
71
+
72
+ err = Validate (y , false )
73
+ assert .Error (t , err , "field `additionalDisks[0].name is invalid`: identifier must not be empty: invalid argument" )
74
+ }
75
+
51
76
func TestValidateParamName (t * testing.T ) {
52
77
images := `images: [{"location": "/"}]`
53
78
validProvision := `provision: [{"script": "echo $PARAM_name $PARAM_NAME $PARAM_Name_123"}]`
You can’t perform that action at this time.
0 commit comments