forked from go-xorm/xorm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
session_raw_test.go
38 lines (30 loc) · 1018 Bytes
/
session_raw_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2017 The Xorm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package xorm
import (
"context"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
func TestExecAndQuery(t *testing.T) {
assert.NoError(t, prepareEngine())
type UserinfoQuery struct {
Uid int
Name string
}
assert.NoError(t, testEngine.Sync2(context.Background(), new(UserinfoQuery)))
res, err := testEngine.Exec(context.Background(), "INSERT INTO `userinfo_query` (uid, name) VALUES (?, ?)", 1, "user")
assert.NoError(t, err)
cnt, err := res.RowsAffected()
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)
results, err := testEngine.Query(context.Background(), "select * from userinfo_query")
assert.NoError(t, err)
assert.EqualValues(t, 1, len(results))
id, err := strconv.Atoi(string(results[0]["uid"]))
assert.NoError(t, err)
assert.EqualValues(t, 1, id)
assert.Equal(t, "user", string(results[0]["name"]))
}