@@ -11,8 +11,10 @@ import (
1111 "fmt"
1212 "os"
1313 "path/filepath"
14+ "strconv"
1415 "strings"
1516 "testing"
17+ "time"
1618
1719 "github.com/openark/golib/tests"
1820
@@ -23,15 +25,21 @@ func TestHooksExecutorExecuteHooks(t *testing.T) {
2325 migrationContext := base .NewMigrationContext ()
2426 migrationContext .AlterStatement = "ENGINE=InnoDB"
2527 migrationContext .DatabaseName = "test"
28+ migrationContext .Hostname = "test.example.com"
2629 migrationContext .OriginalTableName = "tablename"
30+ migrationContext .RowsDeltaEstimate = 1
31+ migrationContext .RowsEstimate = 122
32+ migrationContext .TotalRowsCopied = 123456
33+ migrationContext .SetETADuration (time .Minute )
34+ migrationContext .SetProgressPct (50 )
2735 hooksExecutor := NewHooksExecutor (migrationContext )
2836
29- writeTmpHookFunc := func (testName , hookName , script string ) (hooksPath string , err error ) {
30- if hooksPath , err = os .MkdirTemp ("" , testName ); err != nil {
31- return hooksPath , err
37+ writeTmpHookFunc := func (testName , hookName , script string ) (path string , err error ) {
38+ if path , err = os .MkdirTemp ("" , testName ); err != nil {
39+ return path , err
3240 }
33- err = os .WriteFile (filepath .Join (hooksPath , hookName ), []byte (script ), 0777 )
34- return hooksPath , err
41+ err = os .WriteFile (filepath .Join (path , hookName ), []byte (script ), 0777 )
42+ return path , err
3543 }
3644
3745 t .Run ("does-not-exist" , func (t * testing.T ) {
@@ -71,14 +79,30 @@ func TestHooksExecutorExecuteHooks(t *testing.T) {
7179 for scanner .Scan () {
7280 split := strings .SplitN (scanner .Text (), "=" , 2 )
7381 switch split [0 ] {
82+ case "GH_OST_COPIED_ROWS" :
83+ copiedRows , _ := strconv .ParseInt (split [1 ], 10 , 64 )
84+ tests .S (t ).ExpectEquals (copiedRows , migrationContext .TotalRowsCopied )
7485 case "GH_OST_DATABASE_NAME" :
7586 tests .S (t ).ExpectEquals (split [1 ], migrationContext .DatabaseName )
7687 case "GH_OST_DDL" :
7788 tests .S (t ).ExpectEquals (split [1 ], migrationContext .AlterStatement )
89+ case "GH_OST_DRY_RUN" :
90+ tests .S (t ).ExpectEquals (split [1 ], "false" )
91+ case "GH_OST_ESTIMATED_ROWS" :
92+ estimatedRows , _ := strconv .ParseInt (split [1 ], 10 , 64 )
93+ tests .S (t ).ExpectEquals (estimatedRows , int64 (123 ))
94+ case "GH_OST_ETA_SECONDS" :
95+ etaSeconds , _ := strconv .ParseInt (split [1 ], 10 , 64 )
96+ tests .S (t ).ExpectEquals (etaSeconds , int64 (60 ))
97+ case "GH_OST_EXECUTING_HOST" :
98+ tests .S (t ).ExpectEquals (split [1 ], migrationContext .Hostname )
7899 case "GH_OST_GHOST_TABLE_NAME" :
79100 tests .S (t ).ExpectEquals (split [1 ], fmt .Sprintf ("_%s_gho" , migrationContext .OriginalTableName ))
80101 case "GH_OST_OLD_TABLE_NAME" :
81102 tests .S (t ).ExpectEquals (split [1 ], fmt .Sprintf ("_%s_del" , migrationContext .OriginalTableName ))
103+ case "GH_OST_PROGRESS" :
104+ progress , _ := strconv .ParseFloat (split [1 ], 64 )
105+ tests .S (t ).ExpectEquals (progress , 50.0 )
82106 case "GH_OST_TABLE_NAME" :
83107 tests .S (t ).ExpectEquals (split [1 ], migrationContext .OriginalTableName )
84108 case "TEST" :
0 commit comments