diff --git a/integration/go.mod b/integration/go.mod index 557061e..8e8af4e 100644 --- a/integration/go.mod +++ b/integration/go.mod @@ -1,4 +1,4 @@ -module github.com/poki/mongodb-filter-to-postgres/fuzz +module github.com/poki/mongodb-filter-to-postgres/integration go 1.22.2 diff --git a/integration/postgres_test.go b/integration/postgres_test.go index 0a56768..64a14b3 100644 --- a/integration/postgres_test.go +++ b/integration/postgres_test.go @@ -282,8 +282,8 @@ func TestIntegration_BasicOperators(t *testing.T) { { `unknown column`, `{"foobar": "admin"}`, + []int{}, nil, - errors.New("pq: column \"foobar\" does not exist"), }, { `invalid value`, @@ -301,12 +301,14 @@ func TestIntegration_BasicOperators(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - c := filter.NewConverter(filter.WithArrayDriver(pq.Array)) + c := filter.NewConverter(filter.WithArrayDriver(pq.Array), filter.WithNestedJSONB("metadata", "name", "level", "class", "mount", "items", "parents")) conditions, values, err := c.Convert([]byte(tt.input), 1) if err != nil { t.Fatal(err) } + t.Log(conditions, values) + rows, err := db.Query(` SELECT id FROM players @@ -331,7 +333,7 @@ func TestIntegration_BasicOperators(t *testing.T) { } if !reflect.DeepEqual(players, tt.expectedPlayers) { - t.Fatalf("%q expected %v, got %v (conditions used: %q)", tt.input, tt.expectedPlayers, players, conditions) + t.Fatalf("expected %v, got %v", tt.expectedPlayers, players) } }) } @@ -368,7 +370,7 @@ func TestIntegration_NestedJSONB(t *testing.T) { { "jsonb regex", `{"pet": {"$regex": "^.{3}$"}}`, - []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + []int{1, 2, 3, 4, 5, 6, 7, 8}, }, { "excemption column", diff --git a/integration/setup_test.go b/integration/setup_test.go index 3303b6c..c12bed4 100644 --- a/integration/setup_test.go +++ b/integration/setup_test.go @@ -114,24 +114,27 @@ func createPlayersTable(t *testing.T, db *sql.DB) { "name" text, "metadata" jsonb, "level" int, - "class" text + "class" text, + "mount" text, + "items" text[], + "parents" int[] ); `); err != nil { t.Fatal(err) } if _, err := db.Exec(` - INSERT INTO players ("id", "name", "metadata", "level", "class") - VALUES - (1, 'Alice', '{"guild_id": 20, "pet": "dog"}', 10, 'warrior'), - (2, 'Bob', '{"guild_id": 20, "pet": "cat"}', 20, 'mage'), - (3, 'Charlie', '{"guild_id": 30, "pet": "dog"}', 30, 'rogue'), - (4, 'David', '{"guild_id": 30, "pet": "cat"}', 40, 'warrior'), - (5, 'Eve', '{"guild_id": 40, "pet": "dog"}', 50, 'mage'), - (6, 'Frank', '{"guild_id": 40, "pet": "cat"}', 60, 'rogue'), - (7, 'Grace', '{"guild_id": 50, "pet": "dog"}', 70, 'warrior'), - (8, 'Hank', '{"guild_id": 50, "pet": "cat"}', 80, 'mage'), - (9, 'Ivy', '{"guild_id": 60, "pet": "dog"}', 90, 'rogue'), - (10, 'Jack', '{"guild_id": 60, "pet": "cat"}', 100, 'warrior') + INSERT INTO players + ("id", "name", "metadata", "level", "class", "mount", "items", "parents") VALUES + (1, 'Alice', '{"guild_id": 20, "pet": "dog" }', 10, 'warrior', 'horse', '{}', '{40, 60}'), + (2, 'Bob', '{"guild_id": 20, "pet": "cat", "keys": [1, 3] }', 20, 'mage', 'horse', '{}', '{20, 30}'), + (3, 'Charlie', '{"guild_id": 30, "pet": "dog", "keys": [4, 6] }', 30, 'rogue', NULL, '{}', '{30, 50}'), + (4, 'David', '{"guild_id": 30, "pet": "cat" }', 40, 'warrior', NULL, '{}', '{}'), + (5, 'Eve', '{"guild_id": 40, "pet": "dog", "hats": ["helmet"]}', 50, 'mage', 'griffon', '{"staff", "cloak"}', '{}'), + (6, 'Frank', '{"guild_id": 40, "pet": "cat", "hats": ["cap"] }', 60, 'rogue', 'griffon', '{"dagger"}', '{}'), + (7, 'Grace', '{"guild_id": 50, "pet": "dog" }', 70, 'warrior', 'dragon', '{"sword"}', '{}'), + (8, 'Hank', '{"guild_id": 50, "pet": "cat" }', 80, 'mage', 'dragon', '{}', '{}'), + (9, 'Ivy', '{"guild_id": 60 }', 90, 'rogue', 'phoenix', '{}', '{}'), + (10, 'Jack', '{"guild_id": 60, "pet": null }', 100, 'warrior', 'phoenix', '{}', '{}'); `); err != nil { t.Fatal(err) }