Skip to content

Commit a7cfaa4

Browse files
author
Shlomi Noach
committed
added testing
1 parent 49b80df commit a7cfaa4

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

go/mysql/instance_key_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
Copyright 2016 GitHub Inc.
3+
See https://github.com/github/gh-ost/blob/master/LICENSE
4+
*/
5+
6+
package mysql
7+
8+
import (
9+
"testing"
10+
11+
"github.com/outbrain/golib/log"
12+
test "github.com/outbrain/golib/tests"
13+
)
14+
15+
func init() {
16+
log.SetLevel(log.ERROR)
17+
}
18+
19+
func TestParseInstanceKey(t *testing.T) {
20+
{
21+
key, err := ParseInstanceKey("myhost:1234")
22+
test.S(t).ExpectNil(err)
23+
test.S(t).ExpectEquals(key.Hostname, "myhost")
24+
test.S(t).ExpectEquals(key.Port, 1234)
25+
}
26+
{
27+
key, err := ParseInstanceKey("myhost")
28+
test.S(t).ExpectNil(err)
29+
test.S(t).ExpectEquals(key.Hostname, "myhost")
30+
test.S(t).ExpectEquals(key.Port, 3306)
31+
}
32+
{
33+
key, err := ParseInstanceKey("10.0.0.3:3307")
34+
test.S(t).ExpectNil(err)
35+
test.S(t).ExpectEquals(key.Hostname, "10.0.0.3")
36+
test.S(t).ExpectEquals(key.Port, 3307)
37+
}
38+
{
39+
key, err := ParseInstanceKey("10.0.0.3")
40+
test.S(t).ExpectNil(err)
41+
test.S(t).ExpectEquals(key.Hostname, "10.0.0.3")
42+
test.S(t).ExpectEquals(key.Port, 3306)
43+
}
44+
{
45+
key, err := ParseInstanceKey("[2001:db8:1f70::999:de8:7648:6e8]:3308")
46+
test.S(t).ExpectNil(err)
47+
test.S(t).ExpectEquals(key.Hostname, "2001:db8:1f70::999:de8:7648:6e8")
48+
test.S(t).ExpectEquals(key.Port, 3308)
49+
}
50+
{
51+
_, err := ParseInstanceKey("10.0.0.4:")
52+
test.S(t).ExpectNotNil(err)
53+
}
54+
{
55+
_, err := ParseInstanceKey("10.0.0.4:5.6.7")
56+
test.S(t).ExpectNotNil(err)
57+
}
58+
}

0 commit comments

Comments
 (0)