Skip to content

Commit

Permalink
test(proto): add storage node descriptor validation tests
Browse files Browse the repository at this point in the history
- Added new file: proto/varlogpb/storage_node_test.go
- Includes tests for StorageNodeDescriptor validation
  • Loading branch information
ijsong committed Dec 11, 2024
1 parent ed796f3 commit acf7b7c
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions proto/varlogpb/storage_node_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package varlogpb_test

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/kakao/varlog/proto/varlogpb"
)

func TestStorageNodeDescriptor_Valid(t *testing.T) {
tcs := []struct {
name string
snd *varlogpb.StorageNodeDescriptor
want bool
}{
{
name: "Valid",
snd: &varlogpb.StorageNodeDescriptor{
StorageNode: varlogpb.StorageNode{StorageNodeID: 1, Address: "127.0.0.1"},
Paths: []string{"/path/to/storage"},
},
want: true,
},
{
name: "NilDescriptor",
snd: nil,
want: false,
},
{
name: "EmptyAddress",
snd: &varlogpb.StorageNodeDescriptor{
StorageNode: varlogpb.StorageNode{StorageNodeID: 1, Address: ""},
Paths: []string{"/path/to/storage"},
},
want: false,
},
{
name: "EmptyPaths",
snd: &varlogpb.StorageNodeDescriptor{
StorageNode: varlogpb.StorageNode{StorageNodeID: 1, Address: "127.0.0.1"},
Paths: []string{},
},
want: false,
},
{
name: "EmptyPathInPaths",
snd: &varlogpb.StorageNodeDescriptor{
StorageNode: varlogpb.StorageNode{StorageNodeID: 1, Address: "127.0.0.1"},
Paths: []string{""},
},
want: false,
},
}

for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
got := tc.snd.Valid()
require.Equal(t, tc.want, got)
})
}
}

0 comments on commit acf7b7c

Please sign in to comment.