Test Select node (DML)
(t *testing.T)
| 18 | |
| 19 | // Test Select node (DML) |
| 20 | func TestSelect(t *testing.T) { |
| 21 | tests := []struct { |
| 22 | name string |
| 23 | sel *Select |
| 24 | wantLiteral string |
| 25 | minChildren int |
| 26 | }{ |
| 27 | { |
| 28 | name: "simple SELECT with columns", |
| 29 | sel: &Select{ |
| 30 | Columns: []Expression{ |
| 31 | &Identifier{Name: "id"}, |
| 32 | &Identifier{Name: "name"}, |
| 33 | }, |
| 34 | }, |
| 35 | wantLiteral: "SELECT", |
| 36 | minChildren: 2, |
| 37 | }, |
| 38 | { |
| 39 | name: "SELECT with FROM", |
| 40 | sel: &Select{ |
| 41 | Columns: []Expression{&Identifier{Name: "*"}}, |
| 42 | From: []TableReference{ |
| 43 | {Name: "users"}, |
| 44 | }, |
| 45 | }, |
| 46 | wantLiteral: "SELECT", |
| 47 | minChildren: 2, |
| 48 | }, |
| 49 | { |
| 50 | name: "SELECT with WHERE", |
| 51 | sel: &Select{ |
| 52 | Columns: []Expression{&Identifier{Name: "id"}}, |
| 53 | From: []TableReference{ |
| 54 | {Name: "users"}, |
| 55 | }, |
| 56 | Where: &BinaryExpression{ |
| 57 | Left: &Identifier{Name: "id"}, |
| 58 | Operator: "=", |
| 59 | Right: &LiteralValue{Value: "1"}, |
| 60 | }, |
| 61 | }, |
| 62 | wantLiteral: "SELECT", |
| 63 | minChildren: 3, |
| 64 | }, |
| 65 | { |
| 66 | name: "SELECT with GROUP BY and HAVING", |
| 67 | sel: &Select{ |
| 68 | Columns: []Expression{ |
| 69 | &Identifier{Name: "dept"}, |
| 70 | &FunctionCall{Name: "COUNT", Arguments: []Expression{&Identifier{Name: "*"}}}, |
| 71 | }, |
| 72 | From: []TableReference{ |
| 73 | {Name: "employees"}, |
| 74 | }, |
| 75 | GroupBy: []Expression{&Identifier{Name: "dept"}}, |
| 76 | Having: &BinaryExpression{ |
| 77 | Left: &FunctionCall{Name: "COUNT", Arguments: []Expression{&Identifier{Name: "*"}}}, |
nothing calls this directly
no test coverage detected