-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ident): This update contains some major changes
Separate subprojects Single registration at import Only one ID generator can be registered at a time
- Loading branch information
Showing
11 changed files
with
344 additions
and
7 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
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 |
---|---|---|
@@ -1,9 +1,19 @@ | ||
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0= | ||
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= | ||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
github.com/oklog/ulid/v2 v2.1.0 h1:+9lhoxAP56we25tyYETBBY1YLA2SaoLvUFgrP2miPJU= | ||
github.com/oklog/ulid/v2 v2.1.0/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNsTT1QQ= | ||
github.com/pborman/getopt v0.0.0-20170112200414-7148bc3a4c30/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc= | ||
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= | ||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= | ||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
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
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
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,80 @@ | ||
package snowflake | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/origadmin/toolkits/ident" | ||
) | ||
|
||
func TestSnowflakeGen(t *testing.T) { | ||
s := New() | ||
id := s.Gen() | ||
assert.NotEmpty(t, id) | ||
} | ||
|
||
func TestSnowflakeValidateValidID(t *testing.T) { | ||
s := New() | ||
id := s.Gen() | ||
valid := s.Validate(id) | ||
assert.True(t, valid) | ||
} | ||
|
||
func TestSnowflakeValidateInvalidID(t *testing.T) { | ||
s := New() | ||
invalidID := "invalidID" | ||
valid := s.Validate(invalidID) | ||
assert.False(t, valid) | ||
} | ||
|
||
func TestSnowflakeSize(t *testing.T) { | ||
s := New() | ||
size := s.Size() | ||
assert.Equal(t, bitSize, size) | ||
} | ||
|
||
func TestRegister(t *testing.T) { | ||
if ident.Default() == nil { | ||
t.Errorf("Expected default identifier to be set, but it was not") | ||
} | ||
// Check that the default identifier has been updated | ||
if ident.Default().Name() != "snowflake" { | ||
t.Errorf("Expected default identifier to be updated, but it was not") | ||
} | ||
} | ||
|
||
func TestGenID(t *testing.T) { | ||
// Generate an ID | ||
generatedID := ident.GenID() | ||
|
||
// Check that the generated ID is valid | ||
if !ident.Validate(generatedID) { | ||
t.Errorf("Generated ID is not valid") | ||
} | ||
} | ||
|
||
func TestGenSize(t *testing.T) { | ||
// Check that the size of the generated ID is correct | ||
if ident.Size() != bitSize { | ||
t.Errorf("Expected size of generated ID to be %d, but it was %d", bitSize, ident.Size()) | ||
} | ||
} | ||
|
||
func TestValidate(t *testing.T) { | ||
// Create a new identifier | ||
generator := New() | ||
|
||
// Generate an ID | ||
generatedID := generator.Gen() | ||
|
||
// Check that the generated ID is valid | ||
if !ident.Validate(generatedID) { | ||
t.Errorf("Generated ID is not valid") | ||
} | ||
|
||
// Check that an invalid ID is not valid | ||
if ident.Validate("invalid") { | ||
t.Errorf("Invalid ID is valid") | ||
} | ||
} |
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
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,80 @@ | ||
package ulid | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/origadmin/toolkits/ident" | ||
) | ||
|
||
func TestULIDGen(t *testing.T) { | ||
s := New() | ||
id := s.Gen() | ||
assert.NotEmpty(t, id) | ||
} | ||
|
||
func TestULIDValidateValidID(t *testing.T) { | ||
s := New() | ||
id := s.Gen() | ||
valid := s.Validate(id) | ||
assert.True(t, valid) | ||
} | ||
|
||
func TestULIDValidateInvalidID(t *testing.T) { | ||
s := New() | ||
invalidID := "invalidID" | ||
valid := s.Validate(invalidID) | ||
assert.False(t, valid) | ||
} | ||
|
||
func TestULIDSize(t *testing.T) { | ||
s := New() | ||
size := s.Size() | ||
assert.Equal(t, bitSize, size) | ||
} | ||
|
||
func TestRegister(t *testing.T) { | ||
if ident.Default() == nil { | ||
t.Errorf("Expected default identifier to be set, but it was not") | ||
} | ||
// Check that the default identifier has been updated | ||
if ident.Default().Name() != "ulid" { | ||
t.Errorf("Expected default identifier to be updated, but it was not") | ||
} | ||
} | ||
|
||
func TestGenID(t *testing.T) { | ||
// Generate an ID | ||
generatedID := ident.GenID() | ||
|
||
// Check that the generated ID is valid | ||
if !ident.Validate(generatedID) { | ||
t.Errorf("Generated ID is not valid") | ||
} | ||
} | ||
|
||
func TestGenSize(t *testing.T) { | ||
// Check that the size of the generated ID is correct | ||
if ident.Size() != bitSize { | ||
t.Errorf("Expected size of generated ID to be %d, but it was %d", bitSize, ident.Size()) | ||
} | ||
} | ||
|
||
func TestValidate(t *testing.T) { | ||
// Create a new identifier | ||
generator := New() | ||
|
||
// Generate an ID | ||
generatedID := generator.Gen() | ||
|
||
// Check that the generated ID is valid | ||
if !ident.Validate(generatedID) { | ||
t.Errorf("Generated ID is not valid") | ||
} | ||
|
||
// Check that an invalid ID is not valid | ||
if ident.Validate("invalid") { | ||
t.Errorf("Invalid ID is valid") | ||
} | ||
} |
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
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,80 @@ | ||
package uuid | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/origadmin/toolkits/ident" | ||
) | ||
|
||
func TestUUIDGen(t *testing.T) { | ||
s := New() | ||
id := s.Gen() | ||
assert.NotEmpty(t, id) | ||
} | ||
|
||
func TestUUIDValidateValidID(t *testing.T) { | ||
s := New() | ||
id := s.Gen() | ||
valid := s.Validate(id) | ||
assert.True(t, valid) | ||
} | ||
|
||
func TestUUIDValidateInvalidID(t *testing.T) { | ||
s := New() | ||
invalidID := "invalidID" | ||
valid := s.Validate(invalidID) | ||
assert.False(t, valid) | ||
} | ||
|
||
func TestUUIDSize(t *testing.T) { | ||
s := New() | ||
size := s.Size() | ||
assert.Equal(t, bitSize, size) | ||
} | ||
|
||
func TestRegister(t *testing.T) { | ||
if ident.Default() == nil { | ||
t.Errorf("Expected default identifier to be set, but it was not") | ||
} | ||
// Check that the default identifier has been updated | ||
if ident.Default().Name() != "uuid" { | ||
t.Errorf("Expected default identifier to be updated, but it was not") | ||
} | ||
} | ||
|
||
func TestGenID(t *testing.T) { | ||
// Generate an ID | ||
generatedID := ident.GenID() | ||
|
||
// Check that the generated ID is valid | ||
if !ident.Validate(generatedID) { | ||
t.Errorf("Generated ID is not valid") | ||
} | ||
} | ||
|
||
func TestGenSize(t *testing.T) { | ||
// Check that the size of the generated ID is correct | ||
if ident.Size() != bitSize { | ||
t.Errorf("Expected size of generated ID to be %d, but it was %d", bitSize, ident.Size()) | ||
} | ||
} | ||
|
||
func TestValidate(t *testing.T) { | ||
// Create a new identifier | ||
generator := New() | ||
|
||
// Generate an ID | ||
generatedID := generator.Gen() | ||
|
||
// Check that the generated ID is valid | ||
if !ident.Validate(generatedID) { | ||
t.Errorf("Generated ID is not valid") | ||
} | ||
|
||
// Check that an invalid ID is not valid | ||
if ident.Validate("invalid") { | ||
t.Errorf("Invalid ID is valid") | ||
} | ||
} |
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
Oops, something went wrong.