mirror of
https://github.com/kairos-io/kairos-sdk.git
synced 2025-04-28 03:20:52 +00:00
adjusted query to check if type is null - added test for the case (#114)
Signed-off-by: Anders Kvanvig <anders.kvanvig@basefarm-orange.com> Co-authored-by: Anders Kvanvig <anders.kvanvig@basefarm-orange.com>
This commit is contained in:
parent
c643cb5e73
commit
a5a931958b
@ -489,9 +489,9 @@ func (c Config) Query(s string) (res string, err error) {
|
||||
if err := json.Unmarshal(b, &dat); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// Adding "// empty" to the query so the output does not include a "null" if the value is empty
|
||||
// Adding some jq options to the query so the output does not include "null" if the value is empty
|
||||
// This is not a json parse feature but a string one, so we should return normal values not json specific ones
|
||||
query, err := gojq.Parse(s + "// empty")
|
||||
query, err := gojq.Parse(s + " | if ( . | type) == \"null\" then empty else . end")
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
@ -1095,6 +1095,7 @@ name: Mario
|
||||
|
||||
err = os.WriteFile(path.Join(tmpDir, "local_config.yaml"), []byte(`#cloud-config
|
||||
local_key_1: local_value_1
|
||||
local_key_2: false
|
||||
some:
|
||||
other:
|
||||
key: 3
|
||||
@ -1126,6 +1127,9 @@ some:
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(v).To(Equal("3\n"))
|
||||
Expect(c.Query("options")).To(Equal("foo: bar\n"))
|
||||
v, err = c.Query("local_key_2")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(v).To(Equal("false\n"))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user