From 7322ed1aa4a4570784ffea0f62fc2870265683e0 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Thu, 21 Jan 2021 13:36:35 -0800 Subject: [PATCH] Fix bug in Value.JSON(), with regression test Signed-off-by: Solomon Hykes --- dagger/value.go | 1 + dagger/value_test.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/dagger/value.go b/dagger/value.go index c4b48eb8..64b59a0d 100644 --- a/dagger/value.go +++ b/dagger/value.go @@ -186,6 +186,7 @@ func (v *Value) JSON() JSON { }, nil, ) + out, _ = out.Get(cuePathToStrings(v.Path())...) return out } diff --git a/dagger/value_test.go b/dagger/value_test.go index fde2b312..788276f5 100644 --- a/dagger/value_test.go +++ b/dagger/value_test.go @@ -12,6 +12,23 @@ func TestSimple(t *testing.T) { } } +func TestJSON(t *testing.T) { + cc := &Compiler{} + v, err := cc.Compile("", `foo: hello: "world"`) + if err != nil { + t.Fatal(err) + } + b1 := v.JSON() + if string(b1) != `{"foo":{"hello":"world"}}` { + t.Fatal(b1) + } + // Reproduce a bug where Value.Get().JSON() ignores Get() + b2 := v.Get("foo").JSON() + if string(b2) != `{"hello":"world"}` { + t.Fatal(b2) + } +} + func TestCompileBootScript(t *testing.T) { cc := &Compiler{} cfg, err := cc.Compile("boot.cue", defaultBootScript)