engine_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2017 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 xorm
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestAutoIncrTag(t *testing.T) {
  10. assert.NoError(t, prepareEngine())
  11. type TestAutoIncr1 struct {
  12. Id int64
  13. }
  14. tb := testEngine.TableInfo(new(TestAutoIncr1))
  15. cols := tb.Columns()
  16. assert.EqualValues(t, 1, len(cols))
  17. assert.True(t, cols[0].IsAutoIncrement)
  18. assert.True(t, cols[0].IsPrimaryKey)
  19. assert.Equal(t, "id", cols[0].Name)
  20. type TestAutoIncr2 struct {
  21. Id int64 `xorm:"id"`
  22. }
  23. tb = testEngine.TableInfo(new(TestAutoIncr2))
  24. cols = tb.Columns()
  25. assert.EqualValues(t, 1, len(cols))
  26. assert.False(t, cols[0].IsAutoIncrement)
  27. assert.False(t, cols[0].IsPrimaryKey)
  28. assert.Equal(t, "id", cols[0].Name)
  29. type TestAutoIncr3 struct {
  30. Id int64 `xorm:"'ID'"`
  31. }
  32. tb = testEngine.TableInfo(new(TestAutoIncr3))
  33. cols = tb.Columns()
  34. assert.EqualValues(t, 1, len(cols))
  35. assert.False(t, cols[0].IsAutoIncrement)
  36. assert.False(t, cols[0].IsPrimaryKey)
  37. assert.Equal(t, "ID", cols[0].Name)
  38. type TestAutoIncr4 struct {
  39. Id int64 `xorm:"pk"`
  40. }
  41. tb = testEngine.TableInfo(new(TestAutoIncr4))
  42. cols = tb.Columns()
  43. assert.EqualValues(t, 1, len(cols))
  44. assert.False(t, cols[0].IsAutoIncrement)
  45. assert.True(t, cols[0].IsPrimaryKey)
  46. assert.Equal(t, "id", cols[0].Name)
  47. }