(t *testing.T)
| 156 | } |
| 157 | |
| 158 | func TestDbUnknownTableColumns(t *testing.T) { |
| 159 | t.Parallel() |
| 160 | |
| 161 | dsn := dbal.NewSQLiteTestDatabase(t) |
| 162 | reg, err := New(t.Context(), WithConfigOptions(configx.WithValue("dsn", dsn)), WithAutoMigrate()) |
| 163 | require.NoError(t, err) |
| 164 | |
| 165 | statement := `ALTER TABLE "hydra_client" ADD COLUMN "temp_column" VARCHAR(128) NOT NULL DEFAULT '';` |
| 166 | require.NoError(t, reg.Persister().Connection(t.Context()).RawQuery(statement).Exec()) |
| 167 | |
| 168 | cl := &client.Client{ |
| 169 | ID: strconv.Itoa(rand.Int()), |
| 170 | } |
| 171 | require.NoError(t, reg.Persister().CreateClient(t.Context(), cl)) |
| 172 | getClients := func(ctx context.Context, reg *RegistrySQL) ([]client.Client, error) { |
| 173 | readClients := make([]client.Client, 0) |
| 174 | conn := reg.Persister().Connection(ctx) |
| 175 | cols := popx.DBColumns[client.Client](conn.Dialect) |
| 176 | return readClients, conn.RawQuery(fmt.Sprintf(`SELECT %s, temp_column FROM "hydra_client"`, cols)).All(&readClients) |
| 177 | } |
| 178 | |
| 179 | t.Run("with ignore disabled (default behavior)", func(t *testing.T) { |
| 180 | _, err := getClients(t.Context(), reg) |
| 181 | assert.ErrorContains(t, err, "missing destination name temp_column") |
| 182 | }) |
| 183 | |
| 184 | t.Run("with ignore enabled", func(t *testing.T) { |
| 185 | reg, err := New(t.Context(), WithConfigOptions( |
| 186 | configx.WithValue("dsn", dsn), |
| 187 | configx.WithValue(config.KeyDBIgnoreUnknownTableColumns, true), |
| 188 | )) |
| 189 | require.NoError(t, err) |
| 190 | |
| 191 | actual, err := getClients(t.Context(), reg) |
| 192 | require.NoError(t, err) |
| 193 | assert.Len(t, actual, 1) |
| 194 | }) |
| 195 | } |
| 196 | |
| 197 | func failedPing(err error) func(context.Context, *logrusx.Logger, *sql.BasePersister) error { |
| 198 | return func(context.Context, *logrusx.Logger, *sql.BasePersister) error { |
nothing calls this directly
no test coverage detected