-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented expression patcher
* users can access simply to the record using record.column_name to get the driver encoded value or raw_record.column_name to get a raw string record
- Loading branch information
Showing
2 changed files
with
104 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package toolkit | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestWhenCond_Evaluate(t *testing.T) { | ||
driver := getDriver() | ||
record := NewRecord(driver) | ||
row := &TestRowDriver{ | ||
row: []string{"1", "2023-08-27 00:00:00.000000", "\\N"}, | ||
} | ||
record.SetRow(row) | ||
|
||
type test struct { | ||
name string | ||
when string | ||
expected bool | ||
} | ||
tests := []test{ | ||
{ | ||
name: "int value equal", | ||
when: "record.id == 1", | ||
expected: true, | ||
}, | ||
{ | ||
name: "raw int value equal", | ||
when: "raw_record.id == \"1\"", | ||
expected: true, | ||
}, | ||
{ | ||
name: "is null value check", | ||
when: "record.title == null", | ||
expected: true, | ||
}, | ||
{ | ||
name: "test date cmp", | ||
when: "record.created_at > now()", | ||
expected: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
whenCond, warns := NewWhenCond(tt.when, driver) | ||
require.Empty(t, warns) | ||
res, err := whenCond.Evaluate(record) | ||
require.NoError(t, err) | ||
require.Equal(t, tt.expected, res) | ||
}) | ||
} | ||
} |