Skip to content

Commit

Permalink
Merge pull request #2334 from afbjorklund/limayaml-test
Browse files Browse the repository at this point in the history
Add unittest for pkg/limayaml/default.yaml
  • Loading branch information
jandubois authored Jul 17, 2024
2 parents 1d1ce3c + b84dd65 commit 486b90b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ ssh:
# 🟢 Builtin default: 0 (automatically assigned to a free port)
# NOTE: when the instance name is "default", the builtin default value is set to
# 60022 for backward compatibility.
localPort: 0
localPort: null
# Load ~/.ssh/*.pub in addition to $LIMA_HOME/_config/user.pub .
# This option is useful when you want to use other SSH-based
# applications such as rsync with the Lima instance.
Expand Down
4 changes: 2 additions & 2 deletions pkg/limayaml/limayaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ const (
)

type Rosetta struct {
Enabled *bool `yaml:"enabled" json:"enabled"`
BinFmt *bool `yaml:"binfmt" json:"binfmt"`
Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`
BinFmt *bool `yaml:"binfmt,omitempty" json:"binfmt,omitempty"`
}

type File struct {
Expand Down
43 changes: 43 additions & 0 deletions pkg/limayaml/limayaml_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package limayaml

import (
"encoding/json"
"os"
"testing"

"gotest.tools/v3/assert"
)

func dumpJSON(t *testing.T, d interface{}) string {
b, err := json.Marshal(d)
if err != nil {
t.Fatal(err)
}
return string(b)
}

const emptyYAML = "images: []\n"

func TestEmptyYAML(t *testing.T) {
var y LimaYAML
t.Log(dumpJSON(t, y))
b, err := marshalYAML(y)
assert.NilError(t, err)
assert.Equal(t, string(b), emptyYAML)
}

const defaultYAML = "images: []\n"

func TestDefaultYAML(t *testing.T) {
bytes, err := os.ReadFile("default.yaml")
assert.NilError(t, err)
var y LimaYAML
err = unmarshalYAML(bytes, &y, "")
assert.NilError(t, err)
y.Images = nil // remove default images
y.Mounts = nil // remove default mounts
t.Log(dumpJSON(t, y))
b, err := marshalYAML(y)
assert.NilError(t, err)
assert.Equal(t, string(b), defaultYAML)
}

0 comments on commit 486b90b

Please sign in to comment.