From 0a1f17796e9bfbe993620da9b629d763ce7a8411 Mon Sep 17 00:00:00 2001 From: John Houston Date: Tue, 9 Apr 2024 09:06:29 -0400 Subject: [PATCH 1/3] FIX decoding nil values in manifest_decode() --- internal/framework/provider/functions/decode.go | 2 ++ .../framework/provider/functions/manifest_decode_multi_test.go | 1 + internal/framework/provider/functions/manifest_decode_test.go | 1 + .../framework/provider/functions/testdata/decode_single.yaml | 1 + 4 files changed, 5 insertions(+) diff --git a/internal/framework/provider/functions/decode.go b/internal/framework/provider/functions/decode.go index 79de2a61f1..aaac1de40b 100644 --- a/internal/framework/provider/functions/decode.go +++ b/internal/framework/provider/functions/decode.go @@ -87,6 +87,8 @@ func decodeSequence(ctx context.Context, s []any) (attr.Value, diag.Diagnostics) func decodeScalar(ctx context.Context, m any) (value attr.Value, diags diag.Diagnostics) { switch v := m.(type) { + case nil: + value = types.DynamicNull() case float64: value = types.NumberValue(big.NewFloat(float64(v))) case bool: diff --git a/internal/framework/provider/functions/manifest_decode_multi_test.go b/internal/framework/provider/functions/manifest_decode_multi_test.go index 666365236e..36c390a20b 100644 --- a/internal/framework/provider/functions/manifest_decode_multi_test.go +++ b/internal/framework/provider/functions/manifest_decode_multi_test.go @@ -35,6 +35,7 @@ func TestManifestDecodeMulti(t *testing.T) { }), "kind": knownvalue.StringExact("ConfigMap"), "metadata": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "annotations": knownvalue.Null(), "labels": knownvalue.ObjectExact(map[string]knownvalue.Check{ "test": knownvalue.StringExact("test---label"), }), diff --git a/internal/framework/provider/functions/manifest_decode_test.go b/internal/framework/provider/functions/manifest_decode_test.go index 0c9b1773af..b02507d439 100644 --- a/internal/framework/provider/functions/manifest_decode_test.go +++ b/internal/framework/provider/functions/manifest_decode_test.go @@ -33,6 +33,7 @@ func TestManifestDecode(t *testing.T) { }), "kind": knownvalue.StringExact("ConfigMap"), "metadata": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "annotations": knownvalue.Null(), "labels": knownvalue.ObjectExact(map[string]knownvalue.Check{ "test": knownvalue.StringExact("test---label"), }), diff --git a/internal/framework/provider/functions/testdata/decode_single.yaml b/internal/framework/provider/functions/testdata/decode_single.yaml index c8bf9405cf..282b0b97a1 100644 --- a/internal/framework/provider/functions/testdata/decode_single.yaml +++ b/internal/framework/provider/functions/testdata/decode_single.yaml @@ -6,6 +6,7 @@ apiVersion: v1 kind: ConfigMap metadata: name: test-configmap + annotations: null labels: test: "test---label" data: From 2f14f410a7962ab3905fb95790dd42ff8dfad3af Mon Sep 17 00:00:00 2001 From: John Houston Date: Tue, 9 Apr 2024 09:09:42 -0400 Subject: [PATCH 2/3] Add implicit null to test case --- .../framework/provider/functions/manifest_decode_multi_test.go | 1 + internal/framework/provider/functions/manifest_decode_test.go | 1 + .../framework/provider/functions/testdata/decode_single.yaml | 1 + 3 files changed, 3 insertions(+) diff --git a/internal/framework/provider/functions/manifest_decode_multi_test.go b/internal/framework/provider/functions/manifest_decode_multi_test.go index 36c390a20b..016596bb77 100644 --- a/internal/framework/provider/functions/manifest_decode_multi_test.go +++ b/internal/framework/provider/functions/manifest_decode_multi_test.go @@ -41,6 +41,7 @@ func TestManifestDecodeMulti(t *testing.T) { }), "name": knownvalue.StringExact("test-configmap"), }), + "status": knownvalue.Null(), }), })), }, diff --git a/internal/framework/provider/functions/manifest_decode_test.go b/internal/framework/provider/functions/manifest_decode_test.go index b02507d439..4a2d9e645b 100644 --- a/internal/framework/provider/functions/manifest_decode_test.go +++ b/internal/framework/provider/functions/manifest_decode_test.go @@ -39,6 +39,7 @@ func TestManifestDecode(t *testing.T) { }), "name": knownvalue.StringExact("test-configmap"), }), + "status": knownvalue.Null(), })), }, }, diff --git a/internal/framework/provider/functions/testdata/decode_single.yaml b/internal/framework/provider/functions/testdata/decode_single.yaml index 282b0b97a1..2c89d46c35 100644 --- a/internal/framework/provider/functions/testdata/decode_single.yaml +++ b/internal/framework/provider/functions/testdata/decode_single.yaml @@ -13,3 +13,4 @@ data: configfile: | --- test: document +status: From bc14b438ca2b09764e33bd80d1f607482db36b0a Mon Sep 17 00:00:00 2001 From: John Houston Date: Tue, 9 Apr 2024 09:16:17 -0400 Subject: [PATCH 3/3] Add changelog entry --- .changelog/2461.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/2461.txt diff --git a/.changelog/2461.txt b/.changelog/2461.txt new file mode 100644 index 0000000000..3baeab4851 --- /dev/null +++ b/.changelog/2461.txt @@ -0,0 +1,3 @@ +```release-note:bug +`manifest_decode()`: fix handling of manifests containing null values +```