Skip to content

Commit

Permalink
test: add missing test for proto/snpb.ValidateTopicLogStream
Browse files Browse the repository at this point in the history
  • Loading branch information
ijsong committed Nov 22, 2024
1 parent fc9379e commit e92b816
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions proto/snpb/log_io_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package snpb_test

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"

"github.com/kakao/varlog/pkg/types"
"github.com/kakao/varlog/proto/snpb"
)

func TestValidateTopicLogStream(t *testing.T) {
type testMessage interface {
GetTopicID() types.TopicID
GetLogStreamID() types.LogStreamID
}
tcs := []struct {
msg testMessage
isErr bool
}{
{
msg: &snpb.AppendRequest{
TopicID: types.TopicID(1),
LogStreamID: types.LogStreamID(2),
},
isErr: false,
},
{
msg: &snpb.AppendRequest{
TopicID: types.TopicID(0),
LogStreamID: types.LogStreamID(2),
},
isErr: true,
},
{
msg: &snpb.AppendRequest{
TopicID: types.TopicID(-1),
LogStreamID: types.LogStreamID(2),
},
isErr: true,
},
{
msg: &snpb.AppendRequest{
TopicID: types.TopicID(1),
LogStreamID: types.LogStreamID(0),
},
isErr: true,
},
{
msg: &snpb.AppendRequest{
TopicID: types.TopicID(1),
LogStreamID: types.LogStreamID(-1),
},
isErr: true,
},
}

for _, tc := range tcs {
name := "unknown"
if s, ok := tc.msg.(fmt.Stringer); ok {
name = s.String()
}
t.Run(name, func(t *testing.T) {
err := snpb.ValidateTopicLogStream(tc.msg)
if tc.isErr {
require.Error(t, err)
return
}
require.NoError(t, err)
})
}
}

0 comments on commit e92b816

Please sign in to comment.