Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lima-vm
GitHub Repository: lima-vm/lima
Path: blob/master/pkg/store/store_test.go
2604 views
1
// SPDX-FileCopyrightText: Copyright The Lima Authors
2
// SPDX-License-Identifier: Apache-2.0
3
4
package store
5
6
import (
7
"testing"
8
9
"gotest.tools/v3/assert"
10
11
"github.com/lima-vm/lima/v2/pkg/limatype/dirnames"
12
)
13
14
func TestValidateInstName(t *testing.T) {
15
instNames := []string{
16
"default",
17
"Ubuntu-20.04",
18
"example.com",
19
"under_score",
20
"1-2_3.4",
21
"yml",
22
"yaml",
23
"foo.yaml.com",
24
}
25
for _, arg := range instNames {
26
t.Run(arg, func(t *testing.T) {
27
err := dirnames.ValidateInstName(arg)
28
assert.NilError(t, err)
29
})
30
}
31
invalidIdentifiers := []string{
32
"",
33
"my/instance",
34
"my\\instance",
35
"c:default",
36
"dot.",
37
".dot",
38
"dot..dot",
39
"underscore_",
40
"_underscore",
41
"underscore__underscore",
42
"dash-",
43
"-dash",
44
"dash--dash",
45
}
46
for _, arg := range invalidIdentifiers {
47
t.Run(arg, func(t *testing.T) {
48
err := dirnames.ValidateInstName(arg)
49
assert.ErrorContains(t, err, "not a valid identifier")
50
})
51
}
52
yamlNames := []string{
53
"default.yaml",
54
"MY.YAML",
55
"My.YmL",
56
}
57
for _, arg := range yamlNames {
58
t.Run(arg, func(t *testing.T) {
59
err := dirnames.ValidateInstName(arg)
60
assert.ErrorContains(t, err, "must not end with .y")
61
})
62
}
63
}
64
65