File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import (
1212 "strings"
1313 "unicode"
1414
15+ "github.com/containerd/containerd/identifiers"
1516 "github.com/coreos/go-semver/semver"
1617 "github.com/docker/go-units"
1718 "github.com/lima-vm/lima/pkg/localpathutil"
@@ -136,6 +137,12 @@ func Validate(y *LimaYAML, warn bool) error {
136137 return fmt .Errorf ("field `memory` has an invalid value: %w" , err )
137138 }
138139
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+
139146 for i , f := range y .Mounts {
140147 if ! filepath .IsAbs (f .Location ) && ! strings .HasPrefix (f .Location , "~" ) {
141148 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) {
4848 assert .Error (t , err , "field `probe[0].script` must start with a '#!' line" )
4949}
5050
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+
5176func TestValidateParamName (t * testing.T ) {
5277 images := `images: [{"location": "/"}]`
5378 validProvision := `provision: [{"script": "echo $PARAM_name $PARAM_NAME $PARAM_Name_123"}]`
You can’t perform that action at this time.
0 commit comments