-
Notifications
You must be signed in to change notification settings - Fork 598
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package uuid | ||
|
||
type Generator interface { | ||
NewV1() UUID | ||
NewV2(domaing byte) UUID | ||
NewV3(ns UUID, name string) UUID | ||
NewV4() UUID | ||
NewV5(ns UUID, name string) UUID | ||
} | ||
|
||
type standard struct{} | ||
|
||
func (_ standard) NewV1() UUID { return NewV1() } | ||
func (_ standard) NewV2(domain byte) UUID { return NewV2(domain) } | ||
func (_ standard) NewV3(ns UUID, name string) UUID { return NewV3(ns, name) } | ||
func (_ standard) NewV4() UUID { return NewV4() } | ||
func (_ standard) NewV5(ns UUID, name string) UUID { return NewV5(ns, name) } | ||
|
||
func NewGenerator() Generator { | ||
return standard{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package uuid | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestNewGenerator(t *testing.T) { | ||
generator := NewGenerator() | ||
|
||
u1 := generator.NewV1() | ||
if u1.Version() != 1 { | ||
t.Errorf("UUIDv1 generated with incorrect version: %d", u1.Version()) | ||
} | ||
|
||
u2 := generator.NewV2(DomainPerson) | ||
|
||
if u2.Version() != 2 { | ||
t.Errorf("UUIDv2 generated with incorrect version: %d", u2.Version()) | ||
} | ||
|
||
u3 := generator.NewV3(NamespaceDNS, "www.example.com") | ||
|
||
if u3.Version() != 3 { | ||
t.Errorf("UUIDv3 generated with incorrect version: %d", u3.Version()) | ||
} | ||
|
||
u4 := generator.NewV4() | ||
|
||
if u4.Version() != 4 { | ||
t.Errorf("UUIDv4 generated with incorrect version: %d", u4.Version()) | ||
} | ||
|
||
u5 := generator.NewV5(NamespaceDNS, "www.example.com") | ||
|
||
if u5.Version() != 5 { | ||
t.Errorf("UUIDv3 generated with incorrect version: %d", u5.Version()) | ||
} | ||
|
||
} |