(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestParseMongoShell(t *testing.T) { |
| 13 | testCases := []struct { |
| 14 | description string |
| 15 | statement string |
| 16 | wantStatements int |
| 17 | wantText string |
| 18 | }{ |
| 19 | { |
| 20 | description: "single find statement", |
| 21 | statement: `db.collection.find({})`, |
| 22 | wantStatements: 1, |
| 23 | wantText: `db.collection.find({})`, |
| 24 | }, |
| 25 | { |
| 26 | description: "single find with filter", |
| 27 | statement: `db.users.find({ name: "John" })`, |
| 28 | wantStatements: 1, |
| 29 | wantText: `db.users.find({ name: "John" })`, |
| 30 | }, |
| 31 | { |
| 32 | description: "multiple statements", |
| 33 | statement: "db.users.find({});\ndb.products.insertOne({ name: \"test\" })", |
| 34 | wantStatements: 2, |
| 35 | }, |
| 36 | { |
| 37 | description: "show databases command", |
| 38 | statement: "show dbs", |
| 39 | wantStatements: 1, |
| 40 | }, |
| 41 | { |
| 42 | description: "show collections command", |
| 43 | statement: "show collections", |
| 44 | wantStatements: 1, |
| 45 | }, |
| 46 | { |
| 47 | description: "aggregation pipeline", |
| 48 | statement: `db.orders.aggregate([{ $match: { status: "A" } }, { $group: { _id: "$cust_id", total: { $sum: "$amount" } } }])`, |
| 49 | wantStatements: 1, |
| 50 | }, |
| 51 | { |
| 52 | description: "bracket notation for collection", |
| 53 | statement: `db["my-collection"].find({})`, |
| 54 | wantStatements: 1, |
| 55 | }, |
| 56 | { |
| 57 | description: "method chaining", |
| 58 | statement: `db.users.find({}).sort({ name: 1 }).limit(10)`, |
| 59 | wantStatements: 1, |
| 60 | }, |
| 61 | { |
| 62 | description: "empty input", |
| 63 | statement: "", |
| 64 | wantStatements: 0, |
| 65 | }, |
| 66 | { |
| 67 | description: "whitespace only", |
| 68 | statement: " \n\t ", |
| 69 | wantStatements: 0, |
nothing calls this directly
no test coverage detected