builder_delete_test.go 625 B

123456789101112131415161718192021222324
  1. // Copyright 2018 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package builder
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestBuilderDelete(t *testing.T) {
  10. sql, args, err := Delete(Eq{"a": 1}).From("table1").ToSQL()
  11. assert.NoError(t, err)
  12. assert.EqualValues(t, "DELETE FROM table1 WHERE a=?", sql)
  13. assert.EqualValues(t, []interface{}{1}, args)
  14. }
  15. func TestDeleteNoTable(t *testing.T) {
  16. _, _, err := Delete(Eq{"b": "0"}).ToSQL()
  17. assert.Error(t, err)
  18. assert.EqualValues(t, ErrNoTableName, err)
  19. }