Skip to content

Commit 486b90b

Browse files
authored
Merge pull request #2334 from afbjorklund/limayaml-test
Add unittest for pkg/limayaml/default.yaml
2 parents 1d1ce3c + b84dd65 commit 486b90b

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

examples/default.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ ssh:
125125
# 🟢 Builtin default: 0 (automatically assigned to a free port)
126126
# NOTE: when the instance name is "default", the builtin default value is set to
127127
# 60022 for backward compatibility.
128-
localPort: 0
128+
localPort: null
129129
# Load ~/.ssh/*.pub in addition to $LIMA_HOME/_config/user.pub .
130130
# This option is useful when you want to use other SSH-based
131131
# applications such as rsync with the Lima instance.

pkg/limayaml/limayaml.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ const (
7272
)
7373

7474
type Rosetta struct {
75-
Enabled *bool `yaml:"enabled" json:"enabled"`
76-
BinFmt *bool `yaml:"binfmt" json:"binfmt"`
75+
Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`
76+
BinFmt *bool `yaml:"binfmt,omitempty" json:"binfmt,omitempty"`
7777
}
7878

7979
type File struct {

pkg/limayaml/limayaml_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package limayaml
2+
3+
import (
4+
"encoding/json"
5+
"os"
6+
"testing"
7+
8+
"gotest.tools/v3/assert"
9+
)
10+
11+
func dumpJSON(t *testing.T, d interface{}) string {
12+
b, err := json.Marshal(d)
13+
if err != nil {
14+
t.Fatal(err)
15+
}
16+
return string(b)
17+
}
18+
19+
const emptyYAML = "images: []\n"
20+
21+
func TestEmptyYAML(t *testing.T) {
22+
var y LimaYAML
23+
t.Log(dumpJSON(t, y))
24+
b, err := marshalYAML(y)
25+
assert.NilError(t, err)
26+
assert.Equal(t, string(b), emptyYAML)
27+
}
28+
29+
const defaultYAML = "images: []\n"
30+
31+
func TestDefaultYAML(t *testing.T) {
32+
bytes, err := os.ReadFile("default.yaml")
33+
assert.NilError(t, err)
34+
var y LimaYAML
35+
err = unmarshalYAML(bytes, &y, "")
36+
assert.NilError(t, err)
37+
y.Images = nil // remove default images
38+
y.Mounts = nil // remove default mounts
39+
t.Log(dumpJSON(t, y))
40+
b, err := marshalYAML(y)
41+
assert.NilError(t, err)
42+
assert.Equal(t, string(b), defaultYAML)
43+
}

0 commit comments

Comments
 (0)