Skip to content

Commit b1c9ff7

Browse files
authored
Merge pull request #3680 from alexandear-org/test-validate-min-lima-version
test: Add unit tests for Validate minimumLimaVersion in YAML
2 parents 0ba4a18 + 1d3d678 commit b1c9ff7

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

pkg/limayaml/validate_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"testing"
99

1010
"gotest.tools/v3/assert"
11+
12+
"github.com/lima-vm/lima/pkg/version"
1113
)
1214

1315
func TestValidateEmpty(t *testing.T) {
@@ -17,6 +19,60 @@ func TestValidateEmpty(t *testing.T) {
1719
assert.Error(t, err, "field `images` must be set")
1820
}
1921

22+
func TestValidateMinimumLimaVersion(t *testing.T) {
23+
images := `images: [{"location": "/"}]`
24+
25+
tests := []struct {
26+
name string
27+
currentVersion string
28+
minimumLimaVersion string
29+
wantErr string
30+
}{
31+
{
32+
name: "minimumLimaVersion less than current version",
33+
currentVersion: "1.1.1-114-g5bf5e513",
34+
minimumLimaVersion: "1.1.0",
35+
wantErr: "",
36+
},
37+
{
38+
name: "minimumLimaVersion greater than current version",
39+
currentVersion: "1.1.1-114-g5bf5e513",
40+
minimumLimaVersion: "1.1.2",
41+
wantErr: `template requires Lima version "1.1.2"; this is only "1.1.1"`,
42+
},
43+
{
44+
name: "invalid current version",
45+
currentVersion: "<unknown>",
46+
minimumLimaVersion: "0.8.0",
47+
wantErr: `can't parse builtin Lima version "<unknown>": <unknown> is not in dotted-tri format`,
48+
},
49+
{
50+
name: "invalid minimumLimaVersion",
51+
currentVersion: "1.1.1-114-g5bf5e513",
52+
minimumLimaVersion: "invalid",
53+
wantErr: "field `minimumLimaVersion` must be a semvar value, got \"invalid\": invalid is not in dotted-tri format\ntemplate requires Lima version \"invalid\"; this is only \"1.1.1\"",
54+
},
55+
}
56+
57+
for _, tt := range tests {
58+
t.Run(tt.name, func(t *testing.T) {
59+
oldVersion := version.Version
60+
version.Version = tt.currentVersion
61+
t.Cleanup(func() { version.Version = oldVersion })
62+
63+
y, err := Load([]byte("minimumLimaVersion: "+tt.minimumLimaVersion+"\n"+images), "lima.yaml")
64+
assert.NilError(t, err)
65+
66+
err = Validate(y, false)
67+
if tt.wantErr == "" {
68+
assert.NilError(t, err)
69+
} else {
70+
assert.Error(t, err, tt.wantErr)
71+
}
72+
})
73+
}
74+
}
75+
2076
func TestValidateProbes(t *testing.T) {
2177
images := `images: [{"location": "/"}]`
2278
validProbe := `probes: [{"script": "#!foo"}]`

0 commit comments

Comments
 (0)