mirror of
https://github.com/kairos-io/kairos-sdk.git
synced 2025-04-28 03:20:52 +00:00
* Fix parsing cmdline when keys have a dash If a key has a dash we need to add quotes to it before parsing it with gojq, otherwise it will fail AND the full cmdline will not be parsed! Signed-off-by: Itxaka <itxaka@kairos.io> * Actualizar bootcmdline_test.go --------- Signed-off-by: Itxaka <itxaka@kairos.io>
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
package machine_test
|
|
|
|
import (
|
|
"os"
|
|
|
|
. "github.com/kairos-io/kairos-sdk/machine"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("BootCMDLine", func() {
|
|
Context("parses data", func() {
|
|
|
|
It("returns cmdline if provided", func() {
|
|
f, err := os.CreateTemp("", "test")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
defer os.RemoveAll(f.Name())
|
|
|
|
err = os.WriteFile(f.Name(), []byte(`config_url="foo bar" baz.bar=""`), os.ModePerm)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
b, err := DotToYAML(f.Name())
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(string(b)).To(Equal("baz:\n bar: \"\"\nconfig_url: foo bar\n"), string(b))
|
|
})
|
|
It("works if cmdline contains a dash or underscore", func() {
|
|
f, err := os.CreateTemp("", "test")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
defer os.RemoveAll(f.Name())
|
|
|
|
err = os.WriteFile(f.Name(), []byte(`config-url="foo bar" ba_z.bar=""`), os.ModePerm)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
_, err = DotToYAML(f.Name())
|
|
Expect(err).ToNot(HaveOccurred())
|
|
})
|
|
})
|
|
})
|