diff --git a/internal/template-validator/validation/path/path.go b/internal/template-validator/validation/path/path.go index 75b1167be..643b17bcc 100644 --- a/internal/template-validator/validation/path/path.go +++ b/internal/template-validator/validation/path/path.go @@ -171,7 +171,14 @@ func (r *Results) AsInt64() ([]int64, error) { continue } } - return nil, fmt.Errorf("mismatching type: %v, not int or resource.Quantity", res[j].Type().Name()) + if quantityObj, ok := obj.(*resource.Quantity); ok { + v, ok := quantityObj.AsInt64() + if ok { + ret = append(ret, v) + continue + } + } + return nil, fmt.Errorf("mismatching type: %v, not int or resource.Quantity", res[j].Type()) } } return ret, nil diff --git a/internal/template-validator/validation/path/path_test.go b/internal/template-validator/validation/path/path_test.go index 3e8700342..e60acd8bd 100644 --- a/internal/template-validator/validation/path/path_test.go +++ b/internal/template-validator/validation/path/path_test.go @@ -101,6 +101,22 @@ var _ = Describe("Path", func() { Expect(vals[0]).To(BeNumerically(">", 1024)) }) + It("Should provide integer result for quantity pointer object", func() { + s := "jsonpath::.spec.domain.memory.guest" + p, err := New(s) + Expect(p).To(Not(BeNil())) + Expect(err).ToNot(HaveOccurred()) + + results, err := p.Find(vmCirros) + Expect(err).ToNot(HaveOccurred()) + Expect(results.Len()).To(BeNumerically(">=", 1)) + + vals, err := results.AsInt64() + Expect(err).ToNot(HaveOccurred()) + Expect(vals).To(HaveLen(1)) + Expect(vals[0]).To(BeNumerically(">", 2147483647), "value is lower than 2Gi") + }) + It("Should provide some string results", func() { s := "jsonpath::.spec.domain.machine.type" p, err := New(s) diff --git a/internal/template-validator/validation/test-utils/utils.go b/internal/template-validator/validation/test-utils/utils.go index 490151ab5..5deb89415 100644 --- a/internal/template-validator/validation/test-utils/utils.go +++ b/internal/template-validator/validation/test-utils/utils.go @@ -2,6 +2,7 @@ package test_utils import ( "bytes" + "k8s.io/apimachinery/pkg/util/yaml" kubevirt "kubevirt.io/api/core/v1" @@ -34,6 +35,8 @@ spec: name: cloudinitdisk machine: type: "q35" + memory: + guest: 2Gi resources: requests: memory: 128M