Skip to content

Commit

Permalink
task Fix id-generation (#631)
Browse files Browse the repository at this point in the history
* Fix id-generation

:hear_no_evil: Much sad! 8 hrs of debugging for such a small fix :see_no_evil:

* update stability test

* consistent test

* Revert "update stability test"

This reverts commit 4d5848a.
  • Loading branch information
dacbd authored Aug 2, 2022
1 parent c3f1c08 commit 896354d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion task/common/identifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewRandomIdentifier() Identifier {

func (i Identifier) Long() string {
name := normalize(string(i), maximumLongLength-shortLength-uint32(len("tpi---")))
digest := hash(string(i), shortLength/2)
digest := hash(name, shortLength/2)

return fmt.Sprintf("tpi-%s-%s-%s", name, digest, hash(name+digest, shortLength/2))
}
Expand Down
10 changes: 9 additions & 1 deletion task/common/identifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@ import (

func TestIdentifier(t *testing.T) {
name := gofakeit.NewCrypto().Sentence(512)

t.Run("stability", func(t *testing.T) {
identifier := NewIdentifier(name)

require.Equal(t, identifier.Long(), identifier.Long())
require.Equal(t, identifier.Short(), identifier.Short())
})

t.Run("consistent", func(t *testing.T) {
identifier := NewIdentifier("5299fe10-79e9-4c3b-b15e-036e8e60ab6c")
parsed, err := ParseIdentifier(identifier.Long())

require.NoError(t, err)
require.Equal(t, identifier.Long(), parsed.Long())
require.Equal(t, identifier.Short(), parsed.Short())
})

t.Run("homogeneity", func(t *testing.T) {
identifier := NewIdentifier(name)

Expand Down

0 comments on commit 896354d

Please sign in to comment.