Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: improve coverage for go/bytes2/buffer.go #14958

Merged
merged 6 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions go/bytes2/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,39 @@ package bytes2

import (
"testing"

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

func TestBuffer(t *testing.T) {
b := NewBuffer(nil)

// Test Write function
b.Write([]byte("ab"))
assert.Equal(t, "ab", string(b.Bytes()), "Write()")

// Test WriteString function
b.WriteString("cd")
assert.Equal(t, "abcd", string(b.Bytes()), "WriteString()")

// Test WriteByte function
b.WriteByte('e')
want := "abcde"
if got := string(b.Bytes()); got != want {
t.Errorf("b.Bytes(): %s, want %s", got, want)
}
if got := b.String(); got != want {
t.Errorf("b.String(): %s, want %s", got, want)
}
if got := b.Len(); got != 5 {
t.Errorf("b.Len(): %d, want 5", got)
}
assert.Equal(t, "abcde", string(b.Bytes()), "WriteByte()")

// Test Bytes function
assert.Equal(t, "abcde", string(b.Bytes()))

// Test String function
assert.Equal(t, "abcde", b.String())

// Test StringUnsafe function
assert.Equal(t, "abcde", b.StringUnsafe())

// Test Len function
assert.Equal(t, 5, b.Len())

// Test Reset function
b.Reset()
assert.Equal(t, "", string(b.Bytes()))
assert.Equal(t, 0, b.Len())
}
4 changes: 2 additions & 2 deletions go/vt/vtctl/workflow/switcher_dry_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"strings"
"time"

"vitess.io/vitess/go/maps2"
"golang.org/x/exp/maps"
"vitess.io/vitess/go/mysql/replication"

binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata"
Expand Down Expand Up @@ -380,7 +380,7 @@
}

func (dr *switcherDryRun) initializeTargetSequences(ctx context.Context, sequencesByBackingTable map[string]*sequenceMetadata) error {
sortedBackingTableNames := maps2.Keys(sequencesByBackingTable)
sortedBackingTableNames := maps.Keys(sequencesByBackingTable)

Check warning on line 383 in go/vt/vtctl/workflow/switcher_dry_run.go

View check run for this annotation

Codecov / codecov/patch

go/vt/vtctl/workflow/switcher_dry_run.go#L383

Added line #L383 was not covered by tests
EshaanAgg marked this conversation as resolved.
Show resolved Hide resolved
slices.Sort(sortedBackingTableNames)
dr.drLog.Log(fmt.Sprintf("The following sequence backing tables used by tables being moved will be initialized: %s",
strings.Join(sortedBackingTableNames, ",")))
Expand Down
Loading