Files
kairos-agent/pkg/config/schemas/install_schema_test.go

135 lines
2.6 KiB
Go
Raw Normal View History

seedling: Kairos config validator library (#798) * Validate yaml Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * lint feedback Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Validate User name with JsonSchema Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * WIP users validation Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Add multiple examples for ssh keys Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Add example of complex validation with AnyOf Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Better business rule example with P2P Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Test with message for empty network_token Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Split into a file for each sub section Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Add install schema validations Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Add to main schema Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Add more tests for p2p Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Add install schema Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Validate fields between new and old schema It also adds the missing ones Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Lint Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Remove temp debugging functions Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Add new fields in old schema Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Add documentation for all exported Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Move schemas into a directory of their own Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Add missing dot at end of comment Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Rebase master and add local_file to bundles Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> --------- Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com>
2023-02-08 11:02:13 +01:00
package config_test
import (
"strings"
. "github.com/kairos-io/kairos/pkg/config/schemas"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Install Schema", func() {
var config *KConfig
var err error
var yaml string
JustBeforeEach(func() {
config, err = NewConfigFromYAML(yaml, "#cloud-config", InstallSchema{})
Expect(err).ToNot(HaveOccurred())
})
Context("when device is auto", func() {
BeforeEach(func() {
yaml = `#cloud-config
device: auto`
})
It("succeedes", func() {
Expect(config.IsValid()).To(BeTrue())
})
})
Context("when device is a path", func() {
BeforeEach(func() {
yaml = `#cloud-config
device: /dev/sda`
})
It("succeedes", func() {
Expect(config.IsValid()).To(BeTrue())
})
})
Context("when device is other than a path or auto", func() {
BeforeEach(func() {
yaml = `#cloud-config
device: foobar`
})
It("errors", func() {
Expect(config.IsValid()).NotTo(BeTrue())
Expect(
strings.Contains(config.ValidationError(),
"does not match pattern '^(auto|/|(/[a-zA-Z0-9_-]+)+)$'",
),
).To(BeTrue())
})
})
Context("when reboot and poweroff are true", func() {
BeforeEach(func() {
yaml = `#cloud-config
device: /dev/sda
reboot: true
poweroff: true`
})
It("errors", func() {
Expect(config.IsValid()).NotTo(BeTrue())
Expect(config.ValidationError()).To(MatchRegexp("value must be false"))
})
})
Context("when reboot is true and poweroff is false", func() {
BeforeEach(func() {
yaml = `#cloud-config
device: /dev/sda
reboot: true
poweroff: false`
})
It("succeedes", func() {
Expect(config.IsValid()).To(BeTrue())
})
})
Context("when reboot is false and poweroff is true", func() {
BeforeEach(func() {
yaml = `#cloud-config
device: /dev/sda
reboot: false
poweroff: true`
})
It("succeedes", func() {
Expect(config.IsValid()).To(BeTrue())
})
})
Context("with no power management set", func() {
BeforeEach(func() {
yaml = `#cloud-config
device: /dev/sda`
})
It("succeedes", func() {
Expect(config.IsValid()).To(BeTrue())
})
})
Context("with all possible options", func() {
BeforeEach(func() {
yaml = `#cloud-config
device: "/dev/sda"
reboot: true
auto: true
image: "docker:.."
bundles:
- rootfs_path: /usr/local/lib/extensions/<name>
targets:
- container://<image>
grub_options:
extra_cmdline: "config_url=http://"
extra_active_cmdline: "config_url=http://"
extra_passive_cmdline: "config_url=http://"
default_menu_entry: "foobar"
env:
- foo=barevice: /dev/sda`
})
It("succeedes", func() {
Expect(config.IsValid()).To(BeTrue())
})
})
})