@@ -13,6 +13,7 @@ import (
1313 "github.com/stretchr/testify/assert"
1414
1515 "github.com/github/gh-ost/go/base"
16+ "github.com/github/gh-ost/go/mysql"
1617)
1718
1819func newTestThrottler () * Throttler {
@@ -86,6 +87,40 @@ func TestThrottleReturnsOnContextCancellation(t *testing.T) {
8687 }
8788}
8889
90+ func TestControlReplicaConnectionConfig (t * testing.T ) {
91+ replicaKey := mysql.InstanceKey {Hostname : "replica-host" , Port : 3307 }
92+
93+ t .Run ("uses inspector connection config when not in move-tables mode" , func (t * testing.T ) {
94+ thlr := newTestThrottler ()
95+ thlr .migrationContext .InspectorConnectionConfig .Key = mysql.InstanceKey {Hostname : "source-host" , Port : 3306 }
96+ thlr .migrationContext .InspectorConnectionConfig .User = "source-user"
97+ thlr .migrationContext .InspectorConnectionConfig .Password = "source-pass"
98+
99+ connectionConfig := thlr .controlReplicaConnectionConfig (replicaKey )
100+
101+ assert .False (t , thlr .migrationContext .IsMoveTablesMode ())
102+ assert .Equal (t , replicaKey , connectionConfig .Key )
103+ assert .Equal (t , "source-user" , connectionConfig .User )
104+ assert .Equal (t , "source-pass" , connectionConfig .Password )
105+ })
106+
107+ t .Run ("uses move-tables connection config when in move-tables mode" , func (t * testing.T ) {
108+ thlr := newTestThrottler ()
109+ thlr .migrationContext .MoveTables .TableNames = []string {"my_table" }
110+ thlr .migrationContext .MoveTables .ConnectionConfig = mysql .NewConnectionConfig ()
111+ thlr .migrationContext .MoveTables .ConnectionConfig .Key = mysql.InstanceKey {Hostname : "target-host" , Port : 3306 }
112+ thlr .migrationContext .MoveTables .ConnectionConfig .User = "target-user"
113+ thlr .migrationContext .MoveTables .ConnectionConfig .Password = "target-pass"
114+
115+ connectionConfig := thlr .controlReplicaConnectionConfig (replicaKey )
116+
117+ assert .True (t , thlr .migrationContext .IsMoveTablesMode ())
118+ assert .Equal (t , replicaKey , connectionConfig .Key )
119+ assert .Equal (t , "target-user" , connectionConfig .User )
120+ assert .Equal (t , "target-pass" , connectionConfig .Password )
121+ })
122+ }
123+
89124func TestThrottleCallsOnThrottledCallback (t * testing.T ) {
90125 thlr := newTestThrottler ()
91126 thlr .migrationContext .SetThrottled (true , "test" , base .NoThrottleReasonHint )
0 commit comments