(t *testing.T)
| 162 | } |
| 163 | |
| 164 | func TestExtractMetadata(t *testing.T) { |
| 165 | tree, err := gosqlx.Parse("SELECT u.name, COUNT(*) FROM users u GROUP BY u.name") |
| 166 | if err != nil { |
| 167 | t.Fatalf("parse failed: %v", err) |
| 168 | } |
| 169 | |
| 170 | metadata := gosqlx.ExtractMetadata(tree) |
| 171 | if metadata == nil { |
| 172 | t.Fatal("expected non-nil metadata") |
| 173 | } |
| 174 | |
| 175 | // Check tables |
| 176 | tableSet := make(map[string]bool) |
| 177 | for _, tbl := range metadata.Tables { |
| 178 | tableSet[tbl] = true |
| 179 | } |
| 180 | if !tableSet["users"] { |
| 181 | t.Errorf("expected 'users' in tables, got: %v", metadata.Tables) |
| 182 | } |
| 183 | |
| 184 | // Check columns |
| 185 | colSet := make(map[string]bool) |
| 186 | for _, col := range metadata.Columns { |
| 187 | colSet[col] = true |
| 188 | } |
| 189 | if !colSet["name"] { |
| 190 | t.Errorf("expected 'name' in columns, got: %v", metadata.Columns) |
| 191 | } |
| 192 | |
| 193 | // Check functions |
| 194 | funcSet := make(map[string]bool) |
| 195 | for _, fn := range metadata.Functions { |
| 196 | funcSet[fn] = true |
| 197 | } |
| 198 | if !funcSet["COUNT"] { |
| 199 | t.Errorf("expected 'COUNT' in functions, got: %v", metadata.Functions) |
| 200 | } |
| 201 | |
| 202 | // Check qualified columns contain table qualifier |
| 203 | foundQualified := false |
| 204 | for _, qc := range metadata.ColumnsQualified { |
| 205 | if qc.Table == "u" && qc.Name == "name" { |
| 206 | foundQualified = true |
| 207 | break |
| 208 | } |
| 209 | } |
| 210 | if !foundQualified { |
| 211 | t.Errorf("expected qualified column u.name, got: %v", metadata.ColumnsQualified) |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | // --------------------------------------------------------------------------- |
| 216 | // JSON serialization tests for the C binding structs |
nothing calls this directly
no test coverage detected