MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestComplexityClassification

Function TestComplexityClassification

pkg/advisor/optimizer_test.go:820–891  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

818}
819
820func 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"},

Callers

nothing calls this directly

Calls 3

classifyComplexityFunction · 0.85
RunMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected