go-test/test — pull request #1 by arvenil (2014-11-12 10:48:47+00:00)
Title: Probably broken map comparision

We only check for expected keys, so if we get more keys/values than we expect then IsDeeply ignores that.
I would expect that if I have maps like this:
```
expect = [ "a": 1, "b": 2 ]
got = [ "a": 1, "b": 2, "c": 3 ]
```
then `IsDeeply(got, expect)` should return error, pointing out that we got some values that are not expected.

Provided code is not intended fix, it is just to show the problem (well it probably fixes the problem but a) it's not tested and b) can be probably done better).

Below is an output from go-mysql after applying changes:
```
ok	github.com/percona/go-mysql/event	0.008s
?	github.com/percona/go-mysql/log	[no test files]
[
{
"Offset": 160,
"Ts": "",
"Admin": false,
"Query": "SHOW /*!50002 GLOBAL */ STATUS",
"User": "pt_agent",
"Host": "localhost",
"Db": "",
"TimeMetrics": {
"Lock_time": 5.9e-05,
"Query_time": 0.003953
},
"NumberMetrics": {
"Killed": 0,
"Last_errno": 0,
"Rows_affected": 0,
"Rows_examined": 571,
"Rows_sent": 571
},
"BoolMetrics": {},
"RateType": "",
"RateLimit": 0
}
]

----------------------------------------------------------------------
FAIL: parser_test.go:1334: TestSuite.TestParseSlow016

parser_test.go:1356:
t.Error(diff)
... Error: slice[0].NumberMetrics.map[Last_errno]:
Got a uint64, expected a invalid

[
{
"Offset": 27,
"Ts": "",
"Admin": false,
"Query": "SHOW /*!50002 GLOBAL */ STATUS",
"User": "pt_agent",
"Host": "localhost",
"Db": "",
"TimeMetrics": {
"Lock_time": 5.9e-05,
"Query_time": 0.003953
},
"NumberMetrics": {
"Killed": 0,
"Last_errno": 0,
"Rows_affected": 0,
"Rows_examined": 571,
"Rows_sent": 571
},
"BoolMetrics": {},
"RateType": "",
"RateLimit": 0
}
]

----------------------------------------------------------------------
FAIL: parser_test.go:1361: TestSuite.TestParseSlow017

parser_test.go:1383:
t.Error(diff)
... Error: slice[0].NumberMetrics.map[Last_errno]:
Got a uint64, expected a invalid

[
{
"Offset": 197,
"Ts": "090311 18:11:50",
"Admin": true,
"Query": "Refresh",
"User": "root",
"Host": "localhost",
"Db": "",
"TimeMetrics": {
"Lock_time": 0,
"Query_time": 0.01785
},
"NumberMetrics": {
"Merge_passes": 0,
"Rows_affected": 0,
"Rows_examined": 0,
"Rows_read": 0,
"Rows_sent": 0,
"Thread_id": 47
},
"BoolMetrics": {
"Filesort": false,
"Filesort_on_disk": false,
"Full_join": false,
"Full_scan": false,
"QC_Hit": false,
"Tmp_table": false,
"Tmp_table_on_disk": false
},
"RateType": "",
"RateLimit": 0
}
]

----------------------------------------------------------------------
FAIL: parser_test.go:782: TestSuite.TestParserSlowLog009

parser_test.go:820:
t.Error(diff)
... Error: slice[0].NumberMetrics.map[Rows_affected]:
Got a uint64, expected a invalid

[
{
"Offset": 0,
"Ts": "131128 1:05:31",
"Admin": false,
"Query": "SELECT foo FROM bar WHERE id=1",
"User": "user1",
"Host": "localhost",
"Db": "maindb",
"TimeMetrics": {
"InnoDB_IO_r_wait": 0,
"InnoDB_queue_wait": 0,
"InnoDB_rec_lock_wait": 0,
"Lock_time": 0.000114,
"Query_time": 0.000228
},
"NumberMetrics": {
"Bytes_sent": 545,
"InnoDB_IO_r_bytes": 0,
"InnoDB_IO_r_ops": 0,
"InnoDB_pages_distinct": 2,
"InnoDB_trx_id": 0,
"Killed": 0,
"Last_errno": 0,
"Merge_passes": 0,
"Rows_affected": 0,
"Rows_examined": 1,
"Rows_sent": 1,
"Tmp_disk_tables": 0,
"Tmp_table_sizes": 0,
"Tmp_tables": 0
},
"BoolMetrics": {
"Filesort": false,
"Filesort_on_disk": false,
"Full_join": false,
"Full_scan": false,
"QC_Hit": false,
"Tmp_table": false,
"Tmp_table_on_disk": false
},
"RateType": "query",
"RateLimit": 2
},
{
"Offset": 733,
"Ts": "",
"Admin": false,
"Query": "SELECT foo FROM bar WHERE id=2",
"User": "user1",
"Host": "localhost",
"Db": "maindb",
"TimeMetrics": {
"InnoDB_IO_r_wait": 0,
"InnoDB_queue_wait": 0,
"InnoDB_rec_lock_wait": 0,
"Lock_time": 0.000122,
"Query_time": 0.000237
},
"NumberMetrics": {
"Bytes_sent": 545,
"InnoDB_IO_r_bytes": 0,
"InnoDB_IO_r_ops": 0,
"InnoDB_pages_distinct": 2,
"InnoDB_trx_id": 0,
"Killed": 0,
"Last_errno": 0,
"Merge_passes": 0,
"Rows_affected": 0,
"Rows_examined": 1,
"Rows_sent": 1,
"Tmp_disk_tables": 0,
"Tmp_table_sizes": 0,
"Tmp_tables": 0
},
"BoolMetrics": {
"Filesort": false,
"Filesort_on_disk": false,
"Full_join": false,
"Full_scan": false,
"QC_Hit": false,
"Tmp_table": false,
"Tmp_table_on_disk": false
},
"RateType": "query",
"RateLimit": 2
},
{
"Offset": 1441,
"Ts": "",
"Admin": false,
"Query": "INSERT INTO foo VALUES (NULL, 3)",
"User": "user1",
"Host": "localhost",
"Db": "maindb",
"TimeMetrics": {
"InnoDB_IO_r_wait": 0,
"InnoDB_queue_wait": 0,
"InnoDB_rec_lock_wait": 0,
"Lock_time": 4.8e-05,
"Query_time": 0.000165
},
"NumberMetrics": {
"Bytes_sent": 481,
"InnoDB_IO_r_bytes": 0,
"InnoDB_IO_r_ops": 0,
"InnoDB_pages_distinct": 3,
"InnoDB_trx_id": 0,
"Killed": 0,
"Last_errno": 0,
"Merge_passes": 0,
"Rows_affected": 0,
"Rows_examined": 10,
"Rows_sent": 5,
"Tmp_disk_tables": 0,
"Tmp_table_sizes": 0,
"Tmp_tables": 0
},
"BoolMetrics": {
"Filesort": true,
"Filesort_on_disk": false,
"Full_join": false,
"Full_scan": false,
"QC_Hit": false,
"Tmp_table": false,
"Tmp_table_on_disk": false
},
"RateType": "query",
"RateLimit": 2
}
]

----------------------------------------------------------------------
FAIL: parser_test.go:825: TestSuite.TestParserSlowLog011

parser_test.go:946:
t.Error(diff)
... Error: slice[0].NumberMetrics.map[InnoDB_trx_id]:
Got a uint64, expected a invalid

OOPS: 15 passed, 4 FAILED
--- FAIL: Test (0.03 seconds)
FAIL
FAIL	github.com/percona/go-mysql/log/slow	0.033s
ok	github.com/percona/go-mysql/query	0.004s
?	github.com/percona/go-mysql/test	[no test files]
```