Skip to content

Commit

Permalink
refactor: remove unused function NewClusterIDFromUint (#552)
Browse files Browse the repository at this point in the history
### What this PR does

Remove unused function NewClusterIDFromUint.
  • Loading branch information
ijsong committed Jul 31, 2023
2 parents 1a6a96d + 1c144e1 commit 30168ec
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 26 deletions.
7 changes: 0 additions & 7 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ type ClusterID uint32

var _ fmt.Stringer = (*ClusterID)(nil)

func NewClusterIDFromUint(u uint) (ClusterID, error) {
if u > math.MaxUint32 {
return 0, fmt.Errorf("cluster id overflow %v", u)
}
return ClusterID(u), nil
}

func ParseClusterID(s string) (ClusterID, error) {
id, err := strconv.ParseUint(s, 10, 32)
return ClusterID(id), err
Expand Down
19 changes: 0 additions & 19 deletions pkg/types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package types

import (
"fmt"
"math"
"math/rand"
"strings"
"testing"

Expand All @@ -16,23 +14,6 @@ func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}

func TestClusterID(t *testing.T) {
Convey("ClusterID", t, func() {
Convey("Too large number", func() { // 64bit processor
var number uint = math.MaxUint32 + 1
_, err := NewClusterIDFromUint(number)
So(err, ShouldNotBeNil)
})

Convey("Valid number", func() {
for i := 0; i < 10000; i++ {
_, err := NewClusterIDFromUint(uint(rand.Uint32()))
So(err, ShouldBeNil)
}
})
})
}

func TestTypesStorageNodeID(t *testing.T) {
assert.True(t, StorageNodeID(-1).Invalid())
assert.True(t, StorageNodeID(0).Invalid())
Expand Down

0 comments on commit 30168ec

Please sign in to comment.