mirror of
https://github.com/documize/community.git
synced 2025-07-20 05:39:42 +02:00
updated vendored deps
This commit is contained in:
parent
0ee2903608
commit
62b7b149c1
22 changed files with 1696 additions and 177 deletions
129
vendor/github.com/go-sql-driver/mysql/driver_test.go
generated
vendored
129
vendor/github.com/go-sql-driver/mysql/driver_test.go
generated
vendored
|
@ -171,6 +171,17 @@ func (dbt *DBTest) mustQuery(query string, args ...interface{}) (rows *sql.Rows)
|
|||
return rows
|
||||
}
|
||||
|
||||
func maybeSkip(t *testing.T, err error, skipErrno uint16) {
|
||||
mySQLErr, ok := err.(*MySQLError)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
if mySQLErr.Number == skipErrno {
|
||||
t.Skipf("skipping test for error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmptyQuery(t *testing.T) {
|
||||
runTests(t, dsn, func(dbt *DBTest) {
|
||||
// just a comment, no query
|
||||
|
@ -684,7 +695,7 @@ func TestDateTime(t *testing.T) {
|
|||
for _, setup := range setups.tests {
|
||||
allowBinTime := true
|
||||
if setup.s == "" {
|
||||
// fill time string whereever Go can reliable produce it
|
||||
// fill time string wherever Go can reliable produce it
|
||||
setup.s = setup.t.Format(setups.tlayout)
|
||||
} else if setup.s[0] == '!' {
|
||||
// skip tests using setup.t as source in queries
|
||||
|
@ -856,14 +867,14 @@ func TestNULL(t *testing.T) {
|
|||
dbt.Fatal(err)
|
||||
}
|
||||
if b != nil {
|
||||
dbt.Error("non-nil []byte wich should be nil")
|
||||
dbt.Error("non-nil []byte which should be nil")
|
||||
}
|
||||
// Read non-nil
|
||||
if err = nonNullStmt.QueryRow().Scan(&b); err != nil {
|
||||
dbt.Fatal(err)
|
||||
}
|
||||
if b == nil {
|
||||
dbt.Error("nil []byte wich should be non-nil")
|
||||
dbt.Error("nil []byte which should be non-nil")
|
||||
}
|
||||
// Insert nil
|
||||
b = nil
|
||||
|
@ -1054,22 +1065,36 @@ func TestLoadData(t *testing.T) {
|
|||
dbt.Fatalf("rows count mismatch. Got %d, want 4", i)
|
||||
}
|
||||
}
|
||||
file, err := ioutil.TempFile("", "gotest")
|
||||
defer os.Remove(file.Name())
|
||||
if err != nil {
|
||||
dbt.Fatal(err)
|
||||
}
|
||||
file.WriteString("1\ta string\n2\ta string containing a \\t\n3\ta string containing a \\n\n4\ta string containing both \\t\\n\n")
|
||||
file.Close()
|
||||
|
||||
dbt.db.Exec("DROP TABLE IF EXISTS test")
|
||||
dbt.mustExec("CREATE TABLE test (id INT NOT NULL PRIMARY KEY, value TEXT NOT NULL) CHARACTER SET utf8")
|
||||
|
||||
// Local File
|
||||
file, err := ioutil.TempFile("", "gotest")
|
||||
defer os.Remove(file.Name())
|
||||
if err != nil {
|
||||
dbt.Fatal(err)
|
||||
}
|
||||
RegisterLocalFile(file.Name())
|
||||
|
||||
// Try first with empty file
|
||||
dbt.mustExec(fmt.Sprintf("LOAD DATA LOCAL INFILE %q INTO TABLE test", file.Name()))
|
||||
var count int
|
||||
err = dbt.db.QueryRow("SELECT COUNT(*) FROM test").Scan(&count)
|
||||
if err != nil {
|
||||
dbt.Fatal(err.Error())
|
||||
}
|
||||
if count != 0 {
|
||||
dbt.Fatalf("unexpected row count: got %d, want 0", count)
|
||||
}
|
||||
|
||||
// Then fille File with data and try to load it
|
||||
file.WriteString("1\ta string\n2\ta string containing a \\t\n3\ta string containing a \\n\n4\ta string containing both \\t\\n\n")
|
||||
file.Close()
|
||||
dbt.mustExec(fmt.Sprintf("LOAD DATA LOCAL INFILE %q INTO TABLE test", file.Name()))
|
||||
verifyLoadDataResult()
|
||||
// negative test
|
||||
|
||||
// Try with non-existing file
|
||||
_, err = dbt.db.Exec("LOAD DATA LOCAL INFILE 'doesnotexist' INTO TABLE test")
|
||||
if err == nil {
|
||||
dbt.Fatal("load non-existent file didn't fail")
|
||||
|
@ -1154,11 +1179,9 @@ func TestStrict(t *testing.T) {
|
|||
if conn != nil {
|
||||
conn.Close()
|
||||
}
|
||||
if me, ok := err.(*MySQLError); ok && me.Number == 1231 {
|
||||
// Error 1231: Variable 'sql_mode' can't be set to the value of 'ALLOW_INVALID_DATES'
|
||||
// => skip test, MySQL server version is too old
|
||||
return
|
||||
}
|
||||
// Error 1231: Variable 'sql_mode' can't be set to the value of
|
||||
// 'ALLOW_INVALID_DATES' => skip test, MySQL server version is too old
|
||||
maybeSkip(t, err, 1231)
|
||||
runTests(t, relaxedDsn, func(dbt *DBTest) {
|
||||
dbt.mustExec("CREATE TABLE test (a TINYINT NOT NULL, b CHAR(4))")
|
||||
|
||||
|
@ -1902,3 +1925,77 @@ func TestInterruptBySignal(t *testing.T) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestColumnsReusesSlice(t *testing.T) {
|
||||
rows := mysqlRows{
|
||||
rs: resultSet{
|
||||
columns: []mysqlField{
|
||||
{
|
||||
tableName: "test",
|
||||
name: "A",
|
||||
},
|
||||
{
|
||||
tableName: "test",
|
||||
name: "B",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
allocs := testing.AllocsPerRun(1, func() {
|
||||
cols := rows.Columns()
|
||||
|
||||
if len(cols) != 2 {
|
||||
t.Fatalf("expected 2 columns, got %d", len(cols))
|
||||
}
|
||||
})
|
||||
|
||||
if allocs != 0 {
|
||||
t.Fatalf("expected 0 allocations, got %d", int(allocs))
|
||||
}
|
||||
|
||||
if rows.rs.columnNames == nil {
|
||||
t.Fatalf("expected columnNames to be set, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRejectReadOnly(t *testing.T) {
|
||||
runTests(t, dsn, func(dbt *DBTest) {
|
||||
// Create Table
|
||||
dbt.mustExec("CREATE TABLE test (value BOOL)")
|
||||
// Set the session to read-only. We didn't set the `rejectReadOnly`
|
||||
// option, so any writes after this should fail.
|
||||
_, err := dbt.db.Exec("SET SESSION TRANSACTION READ ONLY")
|
||||
// Error 1193: Unknown system variable 'TRANSACTION' => skip test,
|
||||
// MySQL server version is too old
|
||||
maybeSkip(t, err, 1193)
|
||||
if _, err := dbt.db.Exec("DROP TABLE test"); err == nil {
|
||||
t.Fatalf("writing to DB in read-only session without " +
|
||||
"rejectReadOnly did not error")
|
||||
}
|
||||
// Set the session back to read-write so runTests() can properly clean
|
||||
// up the table `test`.
|
||||
dbt.mustExec("SET SESSION TRANSACTION READ WRITE")
|
||||
})
|
||||
|
||||
// Enable the `rejectReadOnly` option.
|
||||
runTests(t, dsn+"&rejectReadOnly=true", func(dbt *DBTest) {
|
||||
// Create Table
|
||||
dbt.mustExec("CREATE TABLE test (value BOOL)")
|
||||
// Set the session to read only. Any writes after this should error on
|
||||
// a driver.ErrBadConn, and cause `database/sql` to initiate a new
|
||||
// connection.
|
||||
dbt.mustExec("SET SESSION TRANSACTION READ ONLY")
|
||||
// This would error, but `database/sql` should automatically retry on a
|
||||
// new connection which is not read-only, and eventually succeed.
|
||||
dbt.mustExec("DROP TABLE test")
|
||||
})
|
||||
}
|
||||
|
||||
func TestPing(t *testing.T) {
|
||||
runTests(t, dsn, func(dbt *DBTest) {
|
||||
if err := dbt.db.Ping(); err != nil {
|
||||
dbt.fail("Ping", "Ping", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue