From 71e52a8769b6940d92814c9c41f2edad825286ab Mon Sep 17 00:00:00 2001 From: Gusted Date: Mon, 3 Jul 2023 23:44:30 +0200 Subject: [PATCH 1/2] Add unit test for `HashAvatar` - Add 100% unit test for this function. --- modules/avatar/hash_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 modules/avatar/hash_test.go diff --git a/modules/avatar/hash_test.go b/modules/avatar/hash_test.go new file mode 100644 index 0000000000000..0fce24a935cd0 --- /dev/null +++ b/modules/avatar/hash_test.go @@ -0,0 +1,26 @@ +// Copyright 2023 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package avatar_test + +import ( + "bytes" + "image" + "image/png" + "testing" + + "code.gitea.io/gitea/modules/avatar" + + "github.com/stretchr/testify/assert" +) + +func Test_HashAvatar(t *testing.T) { + myImage := image.NewRGBA(image.Rect(0, 0, 32, 32)) + var buff bytes.Buffer + png.Encode(&buff, myImage) + + assert.EqualValues(t, "9ddb5bac41d57e72aa876321d0c09d71090c05f94bc625303801be2f3240d2cb", avatar.HashAvatar(1, buff.Bytes())) + assert.EqualValues(t, "9a5d44e5d637b9582a976676e8f3de1dccd877c2fe3e66ca3fab1629f2f47609", avatar.HashAvatar(8, buff.Bytes())) + assert.EqualValues(t, "ed7399158672088770de6f5211ce15528ebd675e92fc4fc060c025f4b2794ccb", avatar.HashAvatar(1024, buff.Bytes())) + assert.EqualValues(t, "161178642c7d59eb25a61dddced5e6b66eae1c70880d5f148b1b497b767e72d9", avatar.HashAvatar(1024, []byte{})) +} From 143e943583df7f7c5cfbebafd060c6845ff51367 Mon Sep 17 00:00:00 2001 From: Earl Warren <109468362+earl-warren@users.noreply.github.com> Date: Tue, 4 Jul 2023 08:05:02 +0200 Subject: [PATCH 2/2] Update modules/avatar/hash_test.go Co-authored-by: delvh --- modules/avatar/hash_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/avatar/hash_test.go b/modules/avatar/hash_test.go index 0fce24a935cd0..1b8249c696c3a 100644 --- a/modules/avatar/hash_test.go +++ b/modules/avatar/hash_test.go @@ -1,4 +1,4 @@ -// Copyright 2023 The Forgejo Authors. All rights reserved. +// Copyright 2023 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT package avatar_test