Skip to content

Commit

Permalink
use underscore instead of colon for blob store key (#1937)
Browse files Browse the repository at this point in the history
* use underscore instead of colon for blob store key

Signed-off-by: pxp928 <parth.psu@gmail.com>

* add unit tests for getKey

Signed-off-by: pxp928 <parth.psu@gmail.com>

---------

Signed-off-by: pxp928 <parth.psu@gmail.com>
  • Loading branch information
pxp928 committed May 30, 2024
1 parent b1b9a02 commit ccad6b3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func DecodeEventSubject(ctx context.Context, collectedEvent []byte) (string, err

func GetKey(blob []byte) string {
generatedHash := getHash(blob)
return fmt.Sprintf("sha256:%s", generatedHash)
return fmt.Sprintf("sha256_%s", generatedHash)
}

// GetDocRef returns the Document Reference of a blob; i.e. the blob store key for this blob.
Expand Down
40 changes: 40 additions & 0 deletions pkg/events/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,43 @@ func TestCreateEvent(t *testing.T) {
})
}
}

func Test_GetKey(t *testing.T) {
tests := []struct {
name string
key string
want string
}{{
name: "blob",
key: "testKey",
want: "sha256_15291f67d99ea7bc578c3544dadfbb991e66fa69cb36ff70fe30e798e111ff5f",
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
getKey := GetKey([]byte(tt.key))
if getKey != tt.want {
t.Errorf("GetKey() = %v, want %v", getKey, tt.want)
}
})
}
}

func Test_GetDocRef(t *testing.T) {
tests := []struct {
name string
key string
want string
}{{
name: "blob",
key: "testKey",
want: "sha256_15291f67d99ea7bc578c3544dadfbb991e66fa69cb36ff70fe30e798e111ff5f",
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
getKey := GetDocRef([]byte(tt.key))
if getKey != tt.want {
t.Errorf("GetDocRef() = %v, want %v", getKey, tt.want)
}
})
}
}

0 comments on commit ccad6b3

Please sign in to comment.