Skip to content

Commit f274301

Browse files
Updated tests for tableparser
1 parent 7aa9074 commit f274301

File tree

7 files changed

+939
-180
lines changed

7 files changed

+939
-180
lines changed

runtests.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
wait_mysql() {
3+
local PORT=$1
4+
while :
5+
do
6+
sleep 3
7+
if mysql -P ${PORT} -e 'select version()' &>/dev/null; then
8+
break
9+
fi
10+
done
11+
}
12+
13+
for PORT in 3306 3307 3308; do
14+
echo "##########################"
15+
echo "### MySQL at port ${PORT}"
16+
echo "##########################"
17+
wait_mysql $PORT
18+
export TEST_DSN="root:@tcp(127.1:${PORT})/sakila?parseTime=true"
19+
go test -v ./...
20+
done
21+

tableparser/tableparser_test.go

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package tableparser
22

33
import (
4-
"reflect"
54
"testing"
65
"time"
76

@@ -11,49 +10,33 @@ import (
1110
log "github.com/sirupsen/logrus"
1211
)
1312

14-
func TestParse56(t *testing.T) {
13+
func TestParse(t *testing.T) {
1514
db := tu.GetMySQLConnection(t)
16-
v := tu.GetVersion(t, db)
17-
v56, _ := version.NewVersion("5.6")
18-
19-
if v.GreaterThan(v56) {
20-
t.Skipf("This test runs under MySQL < 5.7 and version is %s", v.String())
21-
}
22-
23-
table, err := NewTable(db, "sakila", "film")
24-
if err != nil {
25-
t.Error(err)
26-
}
15+
v := tu.GetMinorVersion(t, db)
2716
var want *Table
28-
tu.LoadJson(t, "table001.json", &want)
2917

30-
if !reflect.DeepEqual(table, want) {
31-
t.Error("Table film was not correctly parsed")
18+
// Patch part of version is stripped by GetMinorVersion so for these test
19+
// it is .0
20+
sampleFiles := map[string]string{
21+
"5.6.0": "table001.json",
22+
"5.7.0": "table002.json",
23+
"8.0.0": "table003.json",
3224
}
33-
}
34-
35-
func TestParse57(t *testing.T) {
36-
db := tu.GetMySQLConnection(t)
37-
v := tu.GetVersion(t, db)
38-
v57, _ := version.NewVersion("5.7")
39-
40-
if v.LessThan(v57) {
41-
t.Skipf("This test runs under MySQL 5.7+ and version is %s", v.String())
25+
sampleFile, ok := sampleFiles[v.String()]
26+
if !ok {
27+
t.Fatalf("Unknown MySQL version %s", v.String())
4228
}
4329

4430
table, err := NewTable(db, "sakila", "film")
4531
if err != nil {
4632
t.Error(err)
4733
}
4834
if tu.UpdateSamples() {
49-
tu.WriteJson(t, "table002.json", table)
35+
tu.WriteJson(t, sampleFile, table)
5036
}
51-
var want *Table
52-
tu.LoadJson(t, "table002.json", &want)
37+
tu.LoadJson(t, sampleFile, &want)
5338

54-
if !reflect.DeepEqual(table, want) {
55-
t.Error("Table film was not correctly parsed")
56-
}
39+
tu.Equals(t, table, want)
5740
}
5841

5942
func TestGetIndexes(t *testing.T) {

tableparser/testdata/indexes.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"PRIMARY": {
33
"Name": "PRIMARY",
4-
"Unique": true,
54
"Fields": [
65
"actor_id"
76
],
7+
"Unique": true,
88
"Visible": true
99
},
1010
"idx_fk_film_id": {
1111
"Name": "idx_fk_film_id",
12-
"Unique": false,
1312
"Fields": [
1413
"film_id"
1514
],
15+
"Unique": false,
1616
"Visible": true
1717
}
1818
}

0 commit comments

Comments
 (0)