From 896354d4674f9f92dd10bc9fc4750b57bf864723 Mon Sep 17 00:00:00 2001 From: Daniel Barnes Date: Tue, 2 Aug 2022 08:33:18 -0700 Subject: [PATCH] `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 4d5848a3bce41291f938602150afc07314c6a24e. --- task/common/identifier.go | 2 +- task/common/identifier_test.go | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/task/common/identifier.go b/task/common/identifier.go index cece190e..805406f2 100644 --- a/task/common/identifier.go +++ b/task/common/identifier.go @@ -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)) } diff --git a/task/common/identifier_test.go b/task/common/identifier_test.go index 1496c4ef..e728e41b 100644 --- a/task/common/identifier_test.go +++ b/task/common/identifier_test.go @@ -9,7 +9,6 @@ import ( func TestIdentifier(t *testing.T) { name := gofakeit.NewCrypto().Sentence(512) - t.Run("stability", func(t *testing.T) { identifier := NewIdentifier(name) @@ -17,6 +16,15 @@ func TestIdentifier(t *testing.T) { 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)