Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
  • Loading branch information
eddycharly committed Sep 19, 2024
1 parent 211203c commit 39e28a1
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 169 deletions.
62 changes: 0 additions & 62 deletions pkg/engine/assert/project.go

This file was deleted.

107 changes: 0 additions & 107 deletions pkg/engine/assert/project_test.go

This file was deleted.

93 changes: 93 additions & 0 deletions pkg/syntax/projection/projection_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package projection

import (
"context"
"testing"

"github.com/jmespath-community/go-jmespath/pkg/binding"
tassert "github.com/stretchr/testify/assert"
)

func TestProjection(t *testing.T) {
tests := []struct {
name string
key any
value any
bindings binding.Bindings
want any
wantErr bool
}{{
name: "map index not found",
key: "foo",
value: map[string]any{
"bar": 42,
},
bindings: nil,
want: nil,
wantErr: false,
}, {
name: "map index found",
key: "bar",
value: map[string]any{
"bar": 42,
},
bindings: nil,
want: 42,
wantErr: false,
}, {
name: "map index found (and nil)",
key: "bar",
value: map[string]any{
"bar": nil,
},
bindings: nil,
want: nil,
wantErr: false,
}, {
name: "non string key (not found)",
key: 3,
value: map[int]any{
2: "foo",
},
bindings: nil,
want: nil,
wantErr: false,
}, {
name: "non string key (found)",
key: 2,
value: map[int]any{
2: "foo",
},
bindings: nil,
want: "foo",
wantErr: false,
}, {
name: "non string key (found and nil)",
key: 2,
value: map[int]any{
2: nil,
},
bindings: nil,
want: nil,
wantErr: false,
}, {
name: "nil value",
key: "foo",
value: nil,
bindings: nil,
want: nil,
wantErr: false,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
proj := Parse(tt.key)
got, err := proj.Handler(context.TODO(), tt.value, tt.bindings)
if tt.wantErr {
tassert.Error(t, err)
} else {
tassert.NoError(t, err)
}
tassert.Equal(t, tt.want, got)
})
}
}

0 comments on commit 39e28a1

Please sign in to comment.