Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions id.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
//
// - Size: 12 bytes (96 bits), smaller than UUID, larger than snowflake
// - Base32 hex encoded by default (16 bytes storage when transported as printable string)
// - Non configured, you don't need set a unique machine and/or data center id
// - Non configured, you don't need to set a unique machine and/or data center id
// - K-ordered
// - Embedded time with 1 second precision
// - Unicity guaranteed for 16,777,216 (24 bits) unique ids per second and per host/process
Expand Down Expand Up @@ -362,12 +362,12 @@ func (id *ID) Scan(value interface{}) (err error) {
}
}

// IsNil Returns true if this is a "nil" ID
// IsNil returns true if this is a "nil" ID
func (id ID) IsNil() bool {
return id == nilID
}

// Alias of IsNil
// IsZero returns true if this is a zero-value ID (alias of IsNil).
func (id ID) IsZero() bool {
return id.IsNil()
}
Expand Down
33 changes: 33 additions & 0 deletions id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,39 @@ func TestID_IsNil(t *testing.T) {
}
}

func TestID_IsZero(t *testing.T) {
tests := []struct {
name string
id ID
want bool
}{
{
name: "ID not zero",
id: New(),
want: false,
},
{
name: "Zero ID",
id: ID{},
want: true,
},
{
name: "NilID helper",
id: NilID(),
want: true,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
if got, want := tt.id.IsZero(), tt.want; got != want {
t.Errorf("IsZero() = %v, want %v", got, want)
}
})
}
}


func TestNilID(t *testing.T) {
got := ID{}
if want := NilID(); !reflect.DeepEqual(got, want) {
Expand Down
Loading