From aade3d42fc0e41e924489209dd44a8fd5974fd9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?= Date: Tue, 30 Jul 2024 16:37:47 +0200 Subject: [PATCH] fix: nil value in projection (#440) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Charles-Edouard Brétéché --- pkg/engine/assert/project.go | 4 +++- pkg/engine/assert/project_test.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/engine/assert/project.go b/pkg/engine/assert/project.go index c79a1102..1a36f81d 100644 --- a/pkg/engine/assert/project.go +++ b/pkg/engine/assert/project.go @@ -32,7 +32,9 @@ func project(ctx context.Context, key any, value any, bindings binding.Bindings, result: projected, }, nil } else { - if reflectutils.GetKind(value) == reflect.Map { + if value == nil { + return nil, nil + } else if reflectutils.GetKind(value) == reflect.Map { mapValue := reflect.ValueOf(value).MapIndex(reflect.ValueOf(expression.statement)) if !mapValue.IsValid() { return nil, nil diff --git a/pkg/engine/assert/project_test.go b/pkg/engine/assert/project_test.go index b7068251..6fb6e8a4 100644 --- a/pkg/engine/assert/project_test.go +++ b/pkg/engine/assert/project_test.go @@ -84,7 +84,7 @@ func Test_project(t *testing.T) { value: nil, bindings: nil, want: nil, - wantErr: true, + wantErr: false, }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {