* Implemented the Compose function to create a Sonyflake ID from its components, including validation for start time, sequence, and machine ID.
* Added a new test, TestCompose, to verify the functionality of the Compose method, ensuring correct decomposition of generated IDs.
* Introduced a new error for invalid sequence numbers to enhance error handling in the Sonyflake package.
* Refactor Sonyflake to use a customizable time function for improved testability. Update currentElapsedTime and sleep methods to utilize the new time function instead of directly calling time.Now().
* Update TimeUnit in ToTime test to use time.Millisecond for improved accuracy in timestamp validation. Adjust time duration comparison to ensure correct validation of generated timestamps.
* Refactor TestNextID to use a customizable time function for improved accuracy in timestamp validation. Adjust time comparison to ensure expected results in generated IDs.
* Refactor TestNextID_InSequence to use a consistent start time for improved clarity in timestamp validation. Update max sequence comparison to ensure accurate validation of generated IDs.
* Refactor tests in sonyflake_test.go to replace fmt.Println with t.Log for better test output management. Update error handling to use errors.New for consistency.
* v2: take only 'bitsMachine' least significant bits from generated machine IDs so it doesn't corrupt the other ID parts (#72)
Co-authored-by: ok32 <e.starikoff@gmail.com>
Co-authored-by: Yoshiyuki Mineo <Yoshiyuki.Mineo@jp.sony.com>
* Refactor Sonyflake Compose method to return errors for invalid parameters and update related tests. Consolidate error handling for start time, sequence, and machine ID validations. Remove unused variable in tests for clarity.
---------
Co-authored-by: ok32 <artuh.gubanova@gmail.com>
Co-authored-by: ok32 <e.starikoff@gmail.com>
* Add v2
* Introduce staticcheck
* Introduce golangci-lint
* Add error checks
* Add error checks
* Lint v2 code
* Improve CI trigger
* Use io.ReadAll
* Use int64
* Remove NewSonyflake
* Fix errors
* v2: Change MachineID, sequence, and AmazonEC2MachineID to int; update all usage and tests for type consistency
* docs: update Settings struct in README to use int for MachineID and CheckMachineID (v2)
* docs(v2): clarify Settings, StartTime, MachineID, and CheckMachineID comments and update README links and explanations
* docs(v2/mock): improve comments and docstrings for mock implementations
* docs(types): unify and clarify package and type docstrings for types.go in v1 and v2
* test(v2): refactor and modernize tests, improve error assertions, and update mocks for v2
* test(v2): normalize whitespace in pseudoSleep calls for consistency
* feat(v2): add configurable TimeUnit and refactor time handling for So… (#67)
* feat(v2): add configurable TimeUnit and refactor time handling for Sonyflake v2
* test(v2): add ToTime tests, clarify TimeUnit behavior, and update docs for v2
* gofmt
* Allow IPv4 Link Local addresses (#50)
* Allow IPv4 Link Local addresses
Allow the use of link local addresses
* Update sonyflake.go
* Update sonyflake.go
* Update a comment
---------
Co-authored-by: Flavio Crisciani <f.crisciani@gmail.com>
* feat(Sonyflake): define error variables
* feat(Sonyflake): add New() function
- minor logic improvements
- return errors
* tests(Sonyflake): remove old TestNilSonyflake test function in favour of the New() function coverage
* gofmt
* Update error messages and comments
* Introduce New function
---------
Co-authored-by: Quetzy Garcia <quetzy.garcia@integrate.com>
* Introduce mocking framework and increase coverage (#22)
This change introduces two common golang patterns:
- types: this will allow fine-tuned control over imported
types by defining where they will be used and how
- mock: this allows the generation of mock constructors,
which allows for testing any individual path in a method by
"injecting" a mock method which matches the expected type
This change also increases test coverage to 100%
Co-authored-by: Yoshiyuki Mineo <Yoshiyuki.Mineo@jp.sony.com>
* gofmt
---------
Co-authored-by: Bradley Boutcher <btboutcher@icloud.com>
* Add sortable test (#11)
* add TestSortableID to make sure that generated ID(s) can be sorted like you are using increment id database
* add TestSortableID to make sure that generated ID(s) can be sorted like you are using increment id database
Co-authored-by: Yoshiyuki Mineo <Yoshiyuki.Mineo@jp.sony.com>
* gofmt
* Check time order explicitly
Co-authored-by: Yusuf Syaifudin <yusuf.syaifudin@gmail.com>