Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lima-vm
GitHub Repository: lima-vm/lima
Path: blob/master/pkg/limayaml/limayaml_test.go
2614 views
1
// SPDX-FileCopyrightText: Copyright The Lima Authors
2
// SPDX-License-Identifier: Apache-2.0
3
4
package limayaml
5
6
import (
7
"bytes"
8
"encoding/json"
9
"os"
10
"path/filepath"
11
"runtime"
12
"testing"
13
14
"gotest.tools/v3/assert"
15
16
"github.com/lima-vm/lima/v2/pkg/limatype"
17
)
18
19
func dumpJSON(t *testing.T, d any) string {
20
b, err := json.Marshal(d)
21
assert.NilError(t, err)
22
return string(b)
23
}
24
25
const emptyYAML = "{}\n"
26
27
func TestEmptyYAML(t *testing.T) {
28
var y limatype.LimaYAML
29
t.Log(dumpJSON(t, y))
30
b, err := Marshal(&y, false)
31
assert.NilError(t, err)
32
assert.Equal(t, string(b), emptyYAML)
33
}
34
35
const defaultYAML = "{}\n"
36
37
func TestDefaultYAML(t *testing.T) {
38
content, err := os.ReadFile("default.yaml")
39
assert.NilError(t, err)
40
// if this is the unresolved symlink as a file, then make sure to resolve it
41
if runtime.GOOS == "windows" && bytes.HasPrefix(content, []byte{'.', '.'}) {
42
f, err := filepath.Rel(".", string(content))
43
assert.NilError(t, err)
44
content, err = os.ReadFile(f)
45
assert.NilError(t, err)
46
}
47
48
var y limatype.LimaYAML
49
err = Unmarshal(content, &y, "")
50
assert.NilError(t, err)
51
y.Images = nil // remove default images
52
y.Mounts = nil // remove default mounts
53
y.Base = nil // remove default base templates
54
y.VMOpts = nil // remove default vmopts mapping
55
y.MinimumLimaVersion = nil // remove minimum Lima version
56
y.MountTypesUnsupported = nil // remove default workaround for kernel 6.9-6.11
57
t.Log(dumpJSON(t, y))
58
b, err := Marshal(&y, false)
59
assert.NilError(t, err)
60
assert.Equal(t, string(b), defaultYAML)
61
}
62
63