(t *testing.T)
| 818 | } |
| 819 | |
| 820 | func TestComplexityClassification(t *testing.T) { |
| 821 | t.Run("nil AST is simple", func(t *testing.T) { |
| 822 | complexity := classifyComplexity(nil) |
| 823 | if complexity != ComplexitySimple { |
| 824 | t.Errorf("expected %q, got %q", ComplexitySimple, complexity) |
| 825 | } |
| 826 | }) |
| 827 | |
| 828 | t.Run("empty AST is simple", func(t *testing.T) { |
| 829 | tree := &ast.AST{} |
| 830 | complexity := classifyComplexity(tree) |
| 831 | if complexity != ComplexitySimple { |
| 832 | t.Errorf("expected %q, got %q", ComplexitySimple, complexity) |
| 833 | } |
| 834 | }) |
| 835 | |
| 836 | t.Run("simple SELECT is simple", func(t *testing.T) { |
| 837 | tree := &ast.AST{ |
| 838 | Statements: []ast.Statement{ |
| 839 | &ast.SelectStatement{ |
| 840 | Columns: []ast.Expression{&ast.Identifier{Name: "id"}}, |
| 841 | From: []ast.TableReference{{Name: "users"}}, |
| 842 | }, |
| 843 | }, |
| 844 | } |
| 845 | complexity := classifyComplexity(tree) |
| 846 | if complexity != ComplexitySimple { |
| 847 | t.Errorf("expected %q, got %q", ComplexitySimple, complexity) |
| 848 | } |
| 849 | }) |
| 850 | |
| 851 | t.Run("SELECT with JOINs is moderate", func(t *testing.T) { |
| 852 | tree := &ast.AST{ |
| 853 | Statements: []ast.Statement{ |
| 854 | &ast.SelectStatement{ |
| 855 | Columns: []ast.Expression{&ast.Identifier{Name: "id"}}, |
| 856 | From: []ast.TableReference{{Name: "users"}}, |
| 857 | Joins: []ast.JoinClause{ |
| 858 | {Type: "INNER"}, |
| 859 | }, |
| 860 | GroupBy: []ast.Expression{&ast.Identifier{Name: "dept"}}, |
| 861 | }, |
| 862 | }, |
| 863 | } |
| 864 | complexity := classifyComplexity(tree) |
| 865 | if complexity != ComplexityModerate { |
| 866 | t.Errorf("expected %q, got %q", ComplexityModerate, complexity) |
| 867 | } |
| 868 | }) |
| 869 | |
| 870 | t.Run("complex query is complex", func(t *testing.T) { |
| 871 | tree := &ast.AST{ |
| 872 | Statements: []ast.Statement{ |
| 873 | &ast.SelectStatement{ |
| 874 | Columns: []ast.Expression{&ast.Identifier{Name: "id"}}, |
| 875 | From: []ast.TableReference{{Name: "users"}}, |
| 876 | Joins: []ast.JoinClause{ |
| 877 | {Type: "INNER"}, |
nothing calls this directly
no test coverage detected