Skip to content

Commit 896354d

Browse files
authored
task Fix id-generation (#631)
* 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.
1 parent c3f1c08 commit 896354d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

task/common/identifier.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func NewRandomIdentifier() Identifier {
4141

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

4646
return fmt.Sprintf("tpi-%s-%s-%s", name, digest, hash(name+digest, shortLength/2))
4747
}

task/common/identifier_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,22 @@ import (
99

1010
func TestIdentifier(t *testing.T) {
1111
name := gofakeit.NewCrypto().Sentence(512)
12-
1312
t.Run("stability", func(t *testing.T) {
1413
identifier := NewIdentifier(name)
1514

1615
require.Equal(t, identifier.Long(), identifier.Long())
1716
require.Equal(t, identifier.Short(), identifier.Short())
1817
})
1918

19+
t.Run("consistent", func(t *testing.T) {
20+
identifier := NewIdentifier("5299fe10-79e9-4c3b-b15e-036e8e60ab6c")
21+
parsed, err := ParseIdentifier(identifier.Long())
22+
23+
require.NoError(t, err)
24+
require.Equal(t, identifier.Long(), parsed.Long())
25+
require.Equal(t, identifier.Short(), parsed.Short())
26+
})
27+
2028
t.Run("homogeneity", func(t *testing.T) {
2129
identifier := NewIdentifier(name)
2230

0 commit comments

Comments
 (0)