(t *testing.T)
| 3031 | } |
| 3032 | |
| 3033 | func TestConvertDropTableToDropView(t *testing.T) { |
| 3034 | tests := []struct { |
| 3035 | name string |
| 3036 | input string |
| 3037 | wantOK bool |
| 3038 | wantChange bool |
| 3039 | }{ |
| 3040 | { |
| 3041 | name: "DROP TABLE IF EXISTS to DROP VIEW IF EXISTS", |
| 3042 | input: `DROP TABLE IF EXISTS "my_schema"."my_view"`, |
| 3043 | wantOK: true, |
| 3044 | wantChange: true, |
| 3045 | }, |
| 3046 | { |
| 3047 | name: "simple DROP TABLE to DROP VIEW", |
| 3048 | input: `DROP TABLE myview`, |
| 3049 | wantOK: true, |
| 3050 | wantChange: true, |
| 3051 | }, |
| 3052 | { |
| 3053 | name: "DROP VIEW unchanged", |
| 3054 | input: `DROP VIEW IF EXISTS myview`, |
| 3055 | wantOK: false, |
| 3056 | wantChange: false, |
| 3057 | }, |
| 3058 | { |
| 3059 | name: "SELECT statement unchanged", |
| 3060 | input: `SELECT * FROM users`, |
| 3061 | wantOK: false, |
| 3062 | wantChange: false, |
| 3063 | }, |
| 3064 | { |
| 3065 | name: "ALTER TABLE unchanged", |
| 3066 | input: `ALTER TABLE users ADD COLUMN email TEXT`, |
| 3067 | wantOK: false, |
| 3068 | wantChange: false, |
| 3069 | }, |
| 3070 | { |
| 3071 | name: "empty string", |
| 3072 | input: ``, |
| 3073 | wantOK: false, |
| 3074 | wantChange: false, |
| 3075 | }, |
| 3076 | { |
| 3077 | name: "invalid SQL", |
| 3078 | input: `NOT VALID SQL AT ALL`, |
| 3079 | wantOK: false, |
| 3080 | wantChange: false, |
| 3081 | }, |
| 3082 | } |
| 3083 | |
| 3084 | for _, tt := range tests { |
| 3085 | t.Run(tt.name, func(t *testing.T) { |
| 3086 | result, ok := ConvertDropTableToDropView(tt.input) |
| 3087 | if ok != tt.wantOK { |
| 3088 | t.Errorf("ConvertDropTableToDropView(%q) ok = %v, want %v", tt.input, ok, tt.wantOK) |
| 3089 | } |
| 3090 | if tt.wantChange { |
nothing calls this directly
no test coverage detected