mirror of
https://github.com/kairos-io/kairos.git
synced 2025-02-09 05:18:51 +00:00

https://go.dev/doc/modules/major-version This way we can bump the kairos dependency on the provider-kairos repo which otherwise produced the error: ``` ~/workspace/kairos/provider-kairos (main)*$ go get -u github.com/kairos-io/kairos@v2.0.0-alpha3 go: github.com/kairos-io/kairos@v2.0.0-alpha3: invalid version: module contains a go.mod file, so module path must match major version ("github.com/kairos-io/kairos/v2") ``` Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> Co-authored-by: Itxaka <itxaka.garcia@spectrocloud.com>
135 lines
2.6 KiB
Go
135 lines
2.6 KiB
Go
package config_test
|
|
|
|
import (
|
|
"strings"
|
|
|
|
. "github.com/kairos-io/kairos/v2/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, 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.Error(),
|
|
"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.Error()).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())
|
|
})
|
|
})
|
|
})
|