Skip to content

Commit

Permalink
add unit test for scanLinesToLogger
Browse files Browse the repository at this point in the history
Signed-off-by: Renan Rangel <rrangel@slack-corp.com>
  • Loading branch information
rvrangel committed Jul 19, 2024
1 parent b74a87f commit c51ee4b
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions go/vt/mysqlctl/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,18 @@ import (
"path"
"reflect"
"sort"
"sync"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/test/utils"

"vitess.io/vitess/go/mysql/replication"

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/mysql/fakesqldb"
"vitess.io/vitess/go/mysql/replication"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/test/utils"
"vitess.io/vitess/go/vt/logutil"
"vitess.io/vitess/go/vt/mysqlctl/backupstats"
"vitess.io/vitess/go/vt/mysqlctl/backupstorage"
Expand Down Expand Up @@ -714,3 +713,26 @@ func TestShouldRestore(t *testing.T) {
assert.False(t, b)
assert.NoError(t, err)
}

func Test_scanLinesToLogger(t *testing.T) {
reader, writer := io.Pipe()
logger := logutil.NewMemoryLogger()
var wg sync.WaitGroup

wg.Add(1)
go scanLinesToLogger("test", reader, logger, wg.Done)

for i := range 100 {
_, err := writer.Write([]byte(fmt.Sprintf("foobar %d\n", i)))
require.NoError(t, err)
}

writer.Close()
wg.Wait()

require.Equal(t, 100, len(logger.Events))

for i, event := range logger.Events {
require.Equal(t, fmt.Sprintf("test: foobar %d", i), event.Value)
}
}

0 comments on commit c51ee4b

Please sign in to comment.