lima icon indicating copy to clipboard operation
lima copied to clipboard

Add unittest for pkg/limayaml/default.yaml

Open afbjorklund opened this issue 1 year ago • 3 comments

Make sure that it is possible to parse default.yaml to the expected LimaYAML structure

Add some minor changes, to make the internal representation (before defaults) "pretty"

Left to do is to remove the default list of architectures, from the default cpuType list:

  • #2333

After that, the default YAML is simply images: [] - since that value is still mandatory.

images: null

With some additional default values and "omitempty", it also matches an empty template.

vmType: null
os: null
arch: null
images: []
cpus: null
memory: null
disk: null
mountType: null
mountInotify: null
additionalDisks: null
ssh:
  localPort: null
  loadDotSSHPubKeys: null
  forwardAgent: null
  forwardX11: null
  forwardX11Trusted: null
caCerts:
  removeDefaults: null
  files: null
  certs: null
upgradePackages: null
containerd:
  system: null
  user: null
cpuType: null
rosetta:
  enabled: null
  binfmt: null
timezone: null
firmware:
  legacyBIOS: null
audio:
  device: null
video:
  display: null
  vnc:
    display: null
networks: null
propagateProxyEnv: null
hostResolver:
  enabled: null
  ipv6: null
  hosts: null
guestInstallPrefix: null
plain: null

afbjorklund avatar May 10 '24 09:05 afbjorklund

~~The unmarshal and marshal functions should probably be refactored into separate files.~~

pkg/limayaml/load.go

pkg/limayaml/limayaml_test.go

I used encoding/json for the test logging, just to avoid dependencies and whitespace...

{"images":null,"ssh":{},"firmware":{},"audio":{},"video":{"vnc":{}},"containerd":{},"hostResolver":{},"caCerts":{},"rosetta":{}}

~~(side note: it seems a bit confused, about marshalling arrays and maps - both objects?)~~


There is a bug in encoding/json, in that there is no empty value for struct... (go issue: 11939)

It doesn't matter here, just makes test log "chatty" ~~(workaround is to replace empty with nil)~~

~~If it bothers anyone, we could have a RemoveDefaults to "undo" the effects of FillDefaults~~

The go-yaml encoder works though, it doesn't add empty structs like the json and the xml do.

afbjorklund avatar May 10 '24 09:05 afbjorklund

Attempt to add separate "Save" functionality:

  • #2338

Also added basic test for "Validate" function:

  • #2337

afbjorklund avatar May 12 '24 10:05 afbjorklund

Could you rebase and squash the commits?

AkihiroSuda avatar Jul 02 '24 06:07 AkihiroSuda