session_iterate_test.go 799 B

1234567891011121314151617181920212223242526272829303132333435363738
  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 TestIterate(t *testing.T) {
  10. assert.NoError(t, prepareEngine())
  11. type UserIterate struct {
  12. Id int64
  13. IsMan bool
  14. }
  15. assert.NoError(t, testEngine.Sync2(new(UserIterate)))
  16. cnt, err := testEngine.Insert(&UserIterate{
  17. IsMan: true,
  18. })
  19. assert.NoError(t, err)
  20. assert.EqualValues(t, 1, cnt)
  21. cnt = 0
  22. err = testEngine.Iterate(new(UserIterate), func(i int, bean interface{}) error {
  23. user := bean.(*UserIterate)
  24. assert.EqualValues(t, 1, user.Id)
  25. assert.EqualValues(t, true, user.IsMan)
  26. cnt++
  27. return nil
  28. })
  29. assert.EqualValues(t, 1, cnt)
  30. }