Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unittest for pkg/limayaml/default.yaml #2334

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

afbjorklund
Copy link
Contributor

@afbjorklund afbjorklund commented May 10, 2024

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:

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
Copy link
Contributor Author

afbjorklund commented May 10, 2024

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 afbjorklund marked this pull request as draft May 12, 2024 10:19
@afbjorklund

This comment was marked as resolved.

Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
@afbjorklund afbjorklund marked this pull request as ready for review May 22, 2024 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant