--------------------------------------------------------------------------- handleFormatSQL ---------------------------------------------------------------------------
(t *testing.T)
| 131 | // --------------------------------------------------------------------------- |
| 132 | |
| 133 | func TestHandleFormatSQL(t *testing.T) { |
| 134 | ctx := context.Background() |
| 135 | |
| 136 | t.Run("valid SQL returns formatted_sql", func(t *testing.T) { |
| 137 | req := makeReq(map[string]any{"sql": "select id from users"}) |
| 138 | res, err := handleFormatSQL(ctx, req) |
| 139 | if err != nil { |
| 140 | t.Fatalf("unexpected error: %v", err) |
| 141 | } |
| 142 | data := unmarshalResult(t, res) |
| 143 | if _, ok := data["formatted_sql"]; !ok { |
| 144 | t.Error("expected 'formatted_sql' key in result") |
| 145 | } |
| 146 | }) |
| 147 | |
| 148 | t.Run("custom options reflected in result", func(t *testing.T) { |
| 149 | req := makeReq(map[string]any{ |
| 150 | "sql": "select id from users", |
| 151 | "indent_size": 4, |
| 152 | "uppercase_keywords": true, |
| 153 | "add_semicolon": true, |
| 154 | }) |
| 155 | res, err := handleFormatSQL(ctx, req) |
| 156 | if err != nil { |
| 157 | t.Fatalf("unexpected error: %v", err) |
| 158 | } |
| 159 | data := unmarshalResult(t, res) |
| 160 | if _, ok := data["formatted_sql"]; !ok { |
| 161 | t.Error("expected 'formatted_sql' key in result") |
| 162 | } |
| 163 | opts, ok := data["options"].(map[string]any) |
| 164 | if !ok { |
| 165 | t.Fatal("expected 'options' map in result") |
| 166 | } |
| 167 | if opts["indent_size"] != float64(4) { |
| 168 | t.Errorf("expected indent_size=4, got %v", opts["indent_size"]) |
| 169 | } |
| 170 | if opts["uppercase_keywords"] != true { |
| 171 | t.Errorf("expected uppercase_keywords=true, got %v", opts["uppercase_keywords"]) |
| 172 | } |
| 173 | if opts["add_semicolon"] != true { |
| 174 | t.Errorf("expected add_semicolon=true, got %v", opts["add_semicolon"]) |
| 175 | } |
| 176 | }) |
| 177 | |
| 178 | t.Run("empty sql returns protocol error", func(t *testing.T) { |
| 179 | req := makeReq(map[string]any{"sql": ""}) |
| 180 | _, err := handleFormatSQL(ctx, req) |
| 181 | if err == nil { |
| 182 | t.Fatal("expected error for empty sql, got nil") |
| 183 | } |
| 184 | }) |
| 185 | |
| 186 | t.Run("missing sql param returns protocol error", func(t *testing.T) { |
| 187 | req := makeReq(map[string]any{}) |
| 188 | _, err := handleFormatSQL(ctx, req) |
| 189 | if err == nil { |
| 190 | t.Fatal("expected error for missing sql param, got nil") |
nothing calls this directly
no test coverage detected