1 package pgconn
2
3 import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7 )
8
9 func TestCommandTag(t *testing.T) {
10 t.Parallel()
11
12 var tests = []struct {
13 commandTag CommandTag
14 rowsAffected int64
15 isInsert bool
16 isUpdate bool
17 isDelete bool
18 isSelect bool
19 }{
20 {commandTag: CommandTag{s: "INSERT 0 5"}, rowsAffected: 5, isInsert: true},
21 {commandTag: CommandTag{s: "UPDATE 0"}, rowsAffected: 0, isUpdate: true},
22 {commandTag: CommandTag{s: "UPDATE 1"}, rowsAffected: 1, isUpdate: true},
23 {commandTag: CommandTag{s: "DELETE 0"}, rowsAffected: 0, isDelete: true},
24 {commandTag: CommandTag{s: "DELETE 1"}, rowsAffected: 1, isDelete: true},
25 {commandTag: CommandTag{s: "DELETE 1234567890"}, rowsAffected: 1234567890, isDelete: true},
26 {commandTag: CommandTag{s: "SELECT 1"}, rowsAffected: 1, isSelect: true},
27 {commandTag: CommandTag{s: "SELECT 99999999999"}, rowsAffected: 99999999999, isSelect: true},
28 {commandTag: CommandTag{s: "CREATE TABLE"}, rowsAffected: 0},
29 {commandTag: CommandTag{s: "ALTER TABLE"}, rowsAffected: 0},
30 {commandTag: CommandTag{s: "DROP TABLE"}, rowsAffected: 0},
31 }
32
33 for i, tt := range tests {
34 ct := tt.commandTag
35 assert.Equalf(t, tt.rowsAffected, ct.RowsAffected(), "%d. %v", i, tt.commandTag)
36 assert.Equalf(t, tt.isInsert, ct.Insert(), "%d. %v", i, tt.commandTag)
37 assert.Equalf(t, tt.isUpdate, ct.Update(), "%d. %v", i, tt.commandTag)
38 assert.Equalf(t, tt.isDelete, ct.Delete(), "%d. %v", i, tt.commandTag)
39 assert.Equalf(t, tt.isSelect, ct.Select(), "%d. %v", i, tt.commandTag)
40 }
41 }
42
View as plain text