added context test, JSON export/import
This commit is contained in:
parent
45b63f6500
commit
fa399e0608
@ -8,6 +8,7 @@ package base
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
@ -256,8 +257,12 @@ func (this *MigrationContext) LoadJSON(jsonString string) error {
|
||||
defer this.throttleMutex.Unlock()
|
||||
|
||||
jsonBytes := []byte(jsonString)
|
||||
err := json.Unmarshal(jsonBytes, this)
|
||||
|
||||
if err := json.Unmarshal(jsonBytes, this); err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
var err error
|
||||
if this.MigrationRangeMinValues, err = sql.NewColumnValuesFromBase64(this.EncodedRangeValues["MigrationRangeMinValues"]); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -271,7 +276,7 @@ func (this *MigrationContext) LoadJSON(jsonString string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetGhostTableName generates the name of ghost table, based on original table name
|
||||
|
54
go/base/context_test.go
Normal file
54
go/base/context_test.go
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
Copyright 2016 GitHub Inc.
|
||||
See https://github.com/github/gh-ost/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package base
|
||||
|
||||
import (
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/outbrain/golib/log"
|
||||
test "github.com/outbrain/golib/tests"
|
||||
|
||||
"github.com/github/gh-ost/go/mysql"
|
||||
"github.com/github/gh-ost/go/sql"
|
||||
)
|
||||
|
||||
func init() {
|
||||
log.SetLevel(log.ERROR)
|
||||
}
|
||||
|
||||
func TestContextToJSON(t *testing.T) {
|
||||
context := NewMigrationContext()
|
||||
jsonString, err := context.ToJSON()
|
||||
test.S(t).ExpectNil(err)
|
||||
test.S(t).ExpectNotEquals(jsonString, "")
|
||||
}
|
||||
|
||||
func TestContextLoadJSON(t *testing.T) {
|
||||
var jsonString string
|
||||
var err error
|
||||
{
|
||||
context := NewMigrationContext()
|
||||
context.AppliedBinlogCoordinates = mysql.BinlogCoordinates{LogFile: "mysql-bin.012345", LogPos: 6789}
|
||||
|
||||
abstractValues := []interface{}{31, "2016-12-24 17:04:32"}
|
||||
context.MigrationRangeMinValues = sql.ToColumnValues(abstractValues)
|
||||
|
||||
jsonString, err = context.ToJSON()
|
||||
test.S(t).ExpectNil(err)
|
||||
test.S(t).ExpectNotEquals(jsonString, "")
|
||||
}
|
||||
{
|
||||
context := NewMigrationContext()
|
||||
err = context.LoadJSON(jsonString)
|
||||
test.S(t).ExpectEqualsAny(err, nil, io.EOF)
|
||||
test.S(t).ExpectEquals(context.AppliedBinlogCoordinates, mysql.BinlogCoordinates{LogFile: "mysql-bin.012345", LogPos: 6789})
|
||||
abstractValues := context.MigrationRangeMinValues.AbstractValues()
|
||||
test.S(t).ExpectEquals(len(abstractValues), 2)
|
||||
test.S(t).ExpectEquals(abstractValues[0], 31)
|
||||
test.S(t).ExpectEquals(abstractValues[1], "2016-12-24 17:04:32")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user