Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Jan 7, 2025
1 parent 8fe55af commit 85389bb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
12 changes: 9 additions & 3 deletions go/mysql/replication/binlog_file_position.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ type BinlogFilePos struct {
}

// ParseBinlogFilePos parses a binlog file and position in the input
// format used by commands such as SHOW REPLICA STATUS and SHOW BINARY
// LOG STATUS.
// format used by internal code that processes output from MySQL such
// as SHOW REPLICA STATUS and SHOW BINARY LOG STATUS.
func ParseBinlogFilePos(s string) (BinlogFilePos, error) {
bfp := BinlogFilePos{}
if s == "" {
return bfp, nil
}

// Split into parts.
file, posStr, ok := strings.Cut(s, ":")
if !ok {
return bfp, fmt.Errorf("invalid binlog file position (%v): expecting file:pos", s)
Expand Down Expand Up @@ -64,3 +66,7 @@ func (bfp BinlogFilePos) ConvertToFlavorPosition() (pos Position, err error) {
pos.GTIDSet, err = ParseFilePosGTIDSet(bfp.String())
return pos, err
}

func (bfp BinlogFilePos) Equal(b BinlogFilePos) bool {
return bfp.File == b.File && bfp.Pos == b.Pos
}
2 changes: 1 addition & 1 deletion go/mysql/replication/replication_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *ReplicationStatus) SQLHealthy() bool {
func ReplicationStatusToProto(s ReplicationStatus) *replicationdatapb.Status {
replstatuspb := &replicationdatapb.Status{
Position: EncodePosition(s.Position),
RelayLogPosition: s.RelayLogPosition.String(),
RelayLogPosition: EncodePosition(s.RelayLogPosition),
FilePosition: s.FilePosition.String(),
RelayLogSourceBinlogEquivalentPosition: s.RelayLogSourceBinlogEquivalentPosition.String(),
SourceServerId: s.SourceServerID,
Expand Down
14 changes: 10 additions & 4 deletions go/mysql/replication/replication_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,16 @@ func TestFilePosRetrieveExecutedPosition(t *testing.T) {
got, err := ParseFilePosReplicationStatus(resultMap)
require.NoError(t, err)
assert.Equalf(t, got.Position.GTIDSet, want.Position.GTIDSet, "got Position: %v; want Position: %v", got.Position.GTIDSet, want.Position.GTIDSet)
assert.Equalf(t, got.RelayLogPosition.GTIDSet, want.RelayLogPosition, "got RelayLogPosition: %v; want RelayLogPosition: %v", got.RelayLogPosition.GTIDSet, want.RelayLogPosition.GTIDSet)
assert.Equalf(t, got.RelayLogPosition.GTIDSet, want.RelayLogPosition.GTIDSet, "got RelayLogPosition: %v; want RelayLogPosition: %v", got.RelayLogPosition.GTIDSet, want.RelayLogPosition.GTIDSet)
assert.Equalf(t, got.RelayLogFilePosition, want.RelayLogFilePosition, "got RelayLogFilePosition: %v; want RelayLogFilePosition: %v", got.RelayLogFilePosition, want.RelayLogFilePosition)
assert.Equalf(t, got.FilePosition, want.FilePosition, "got FilePosition: %v; want FilePosition: %v", got.FilePosition, want.FilePosition)
assert.Equalf(t, got.RelayLogSourceBinlogEquivalentPosition, want.RelayLogSourceBinlogEquivalentPosition, "got RelayLogSourceBinlogEquivalentPosition: %v; want RelayLogSourceBinlogEquivalentPosition: %v", got.RelayLogSourceBinlogEquivalentPosition, want.RelayLogSourceBinlogEquivalentPosition)
assert.Equalf(t, got.Position.GTIDSet, got.FilePosition, "FilePosition and Position don't match when they should for the FilePos flavor")
assert.Equalf(t, got.RelayLogPosition.GTIDSet, got.RelayLogSourceBinlogEquivalentPosition, "RelayLogPosition and RelayLogSourceBinlogEquivalentPosition don't match when they should for the FilePos flavor")
filePos, err := got.FilePosition.ConvertToFlavorPosition()
require.NoError(t, err)
assert.Equalf(t, got.Position.GTIDSet, filePos.GTIDSet, "FilePosition and Position don't match when they should for the FilePos flavor")
filePos, err = got.RelayLogSourceBinlogEquivalentPosition.ConvertToFlavorPosition()
require.NoError(t, err)
assert.Equalf(t, got.RelayLogPosition.GTIDSet, filePos.GTIDSet, "RelayLogPosition and RelayLogSourceBinlogEquivalentPosition don't match when they should for the FilePos flavor")
}

func TestFilePosShouldGetPosition(t *testing.T) {
Expand All @@ -332,5 +336,7 @@ func TestFilePosShouldGetPosition(t *testing.T) {
require.NoError(t, err)
assert.Equalf(t, got.Position.GTIDSet, want.Position.GTIDSet, "got Position: %v; want Position: %v", got.Position.GTIDSet, want.Position.GTIDSet)
assert.Equalf(t, got.FilePosition, want.FilePosition, "got FilePosition: %v; want FilePosition: %v", got.FilePosition, want.FilePosition)
assert.Equalf(t, got.Position.GTIDSet, got.FilePosition, "FilePosition and Position don't match when they should for the FilePos flavor")
filePos, err := got.FilePosition.ConvertToFlavorPosition()
require.NoError(t, err)
assert.Equalf(t, got.Position.GTIDSet, filePos.GTIDSet, "FilePosition and Position don't match when they should for the FilePos flavor")
}

0 comments on commit 85389bb

Please sign in to comment.