Skip to content

Commit

Permalink
object: Improve testing and increase coverage for Type
Browse files Browse the repository at this point in the history
Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Oct 31, 2024
1 parent c24b865 commit 5030278
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions object/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,23 @@ func TestType_ToV2(t *testing.T) {
}
}

func TestTypeProto(t *testing.T) {
for x, y := range map[v2object.Type]object.Type{
v2object.TypeRegular: object.TypeRegular,
v2object.TypeTombstone: object.TypeTombstone,
v2object.TypeStorageGroup: object.TypeStorageGroup,
v2object.TypeLock: object.TypeLock,
v2object.TypeLink: object.TypeLink,
} {
require.EqualValues(t, x, y)
}
}

func TestType_String(t *testing.T) {
for r, s := range typeStrings {
require.Equal(t, s, r.String())
}

toPtr := func(v object.Type) *object.Type {
return &v
}
Expand Down Expand Up @@ -96,3 +112,23 @@ func testEnumStrings(t *testing.T, e enumIface, items []enumStringItem) {
require.False(t, e.DecodeString(str))
}
}

func TestTypeToString(t *testing.T) {
for n, s := range typeStrings {
require.Equal(t, s, object.TypeToString(n))
}
}

func TestTypeFromString(t *testing.T) {
t.Run("invalid", func(t *testing.T) {
for _, s := range []string{"", "foo", "1.2"} {
_, ok := object.TypeFromString(s)
require.False(t, ok, s)
}
})
for n, s := range typeStrings {
v, ok := object.TypeFromString(s)
require.True(t, ok)
require.Equal(t, n, v)
}
}

0 comments on commit 5030278

Please sign in to comment.