Skip to content

Commit

Permalink
chore: improve tests and fix cel gen exports
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Dec 14, 2023
1 parent e6a8b58 commit 618dd24
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 32 deletions.
28 changes: 23 additions & 5 deletions funcs/cel_exports.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 28 additions & 21 deletions funcs/coll_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion funcs/data_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 34 additions & 5 deletions tests/cel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ func runTests(t *testing.T, tests []Test) {
}
}

func TestColl(t *testing.T) {
runTests(t, []Test{
{nil, `Dict(['a','b', 'c', 'd']).a`, "b"},
{nil, `Dict(['a','b', 'c', 'd']).c`, "d"},
{nil, `Has(['a','b', 'c'], 'a')`, "true"},
{nil, `Has(['a','b', 'c'], 'e')`, "false"},
})
}

func TestCrypto(t *testing.T) {
runTests(t, []Test{
{nil, `crypto.SHA1('hello')`, "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d"},
{nil, `crypto.SHA224('hello')`, "ea09ae9cc6768c50fcee903ed054556e5bfc8347907f12598aa24193"},
{nil, `crypto.SHA256('hello')`, "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"},
{nil, `crypto.SHA384('hello')`, "59e1748777448c69de6b800d7a33bbfb9ff1b463e44354c3553bcdb9c666fa90125a3c79f90397bdf5f6a13de828684f"},
{nil, `crypto.SHA512('hello')`, "9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043"},
})
}

func TestFunctions(t *testing.T) {
funcs := map[string]func() any{
"fn": func() any {
Expand Down Expand Up @@ -125,10 +144,13 @@ func TestLists(t *testing.T) {
func TestAws(t *testing.T) {
runTests(t, []Test{
{nil, "arnToMap('arn:aws:sns:eu-west-1:123:MMS-Topic').account", "123"},
{map[string]interface{}{"x": []map[string]string{
{"Name": "hello", "Value": "world"},
{"Name": "John", "Value": "Doe"},
}}, "fromAWSMap(x).hello", "world"},
{map[string]interface{}{
"x": []map[string]string{
{"Name": "hello", "Value": "world"},
{"Name": "John", "Value": "Doe"},
},
},
"fromAWSMap(x).hello", "world"},
})
}

Expand Down Expand Up @@ -172,7 +194,8 @@ func unstructure(o any) interface{} {
func TestData(t *testing.T) {
person := Person{
Name: "Aditya",
Address: &Address{City: "Kathmandu"}}
Address: &Address{City: "Kathmandu"},
}
runTests(t, []Test{
{map[string]interface{}{"i": newFolderCheck(1)}, "i.files[0].modified", testDate},
{nil, `dyn([{'name': 'John', 'age': 30}]).toJSON()`, `[{"age":30,"name":"John"}]`},
Expand All @@ -185,6 +208,11 @@ func TestData(t *testing.T) {
{map[string]interface{}{"i": person}, "JSON(toJSON(i)).name", "Aditya"},
{map[string]interface{}{"i": person}, "JSON(i.toJSON()).name", "Aditya"},
{map[string]interface{}{"i": person}, "YAML(toYAML(i)).name", "Aditya"},
{map[string]interface{}{"i": person}, `JSONArray('["1", "2"]')[0]`, "1"},
{map[string]interface{}{"i": map[string]string{"name": "aditya"}}, `toJSON(i)`, `{"name":"aditya"}`},
// csv
{nil, `CSV(["Alice,30", "Bob,31"])[0][0]`, "Alice"},
{nil, `data.CSVByRow(["sn,name,age,gender", "1,Alice,30,f", "2,Bob,31,m"])`, "Alice"},
// TOML doesn't use JSON tags,
{map[string]interface{}{"i": person}, "TOML(toTOML(i)).Address.city_name", "Kathmandu"},
{structEnv, `results.Address.city_name == "Kathmandu" && results.name == "Aditya"`, "true"},
Expand All @@ -209,6 +237,7 @@ func TestExtensions(t *testing.T) {
{nil, `[1,2,3,4].slice(1, 3)`, "[2 3]"}, // lists lib
})
}

func TestStrings(t *testing.T) {
tests := []Test{
{nil, `random.AlphaNum(10).size()`, "10"},
Expand Down

0 comments on commit 618dd24

Please sign in to comment.