From e68b9d00a6e05b3a941f63ffb696f91e554ac5ec Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 18 Oct 2024 20:33:49 +0200 Subject: Adding upstream version 9.0.3. Signed-off-by: Daniel Baumann --- modules/git/object_id_test.go | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 modules/git/object_id_test.go (limited to 'modules/git/object_id_test.go') diff --git a/modules/git/object_id_test.go b/modules/git/object_id_test.go new file mode 100644 index 0000000..00a24e3 --- /dev/null +++ b/modules/git/object_id_test.go @@ -0,0 +1,49 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package git + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestIsValidSHAPattern(t *testing.T) { + h := Sha1ObjectFormat + assert.True(t, h.IsValid("fee1")) + assert.True(t, h.IsValid("abc000")) + assert.True(t, h.IsValid("9023902390239023902390239023902390239023")) + assert.False(t, h.IsValid("90239023902390239023902390239023902390239023")) + assert.False(t, h.IsValid("abc")) + assert.False(t, h.IsValid("123g")) + assert.False(t, h.IsValid("some random text")) + + assert.Equal(t, "79ee38a6416c1ede423ec7ee0a8639ceea4aad22", ComputeBlobHash(Sha1ObjectFormat, []byte("some random blob")).String()) + assert.Equal(t, "d5c6407415d85df49592672aa421aed39b9db5e3", ComputeBlobHash(Sha1ObjectFormat, []byte("same length blob")).String()) + assert.Equal(t, "df0b5174ed06ae65aea40d43316bcbc21d82c9e3158ce2661df2ad28d7931dd6", ComputeBlobHash(Sha256ObjectFormat, []byte("some random blob")).String()) +} + +func TestIsEmptyCommitID(t *testing.T) { + assert.True(t, IsEmptyCommitID("", nil)) + assert.True(t, IsEmptyCommitID("", Sha1ObjectFormat)) + assert.True(t, IsEmptyCommitID("", Sha256ObjectFormat)) + + assert.False(t, IsEmptyCommitID("79ee38a6416c1ede423ec7ee0a8639ceea4aad20", Sha1ObjectFormat)) + assert.True(t, IsEmptyCommitID("0000000000000000000000000000000000000000", nil)) + assert.True(t, IsEmptyCommitID("0000000000000000000000000000000000000000", Sha1ObjectFormat)) + assert.False(t, IsEmptyCommitID("0000000000000000000000000000000000000000", Sha256ObjectFormat)) + + assert.False(t, IsEmptyCommitID("00000000000000000000000000000000000000000", nil)) + + assert.False(t, IsEmptyCommitID("0f0b5174ed06ae65aea40d43316bcbc21d82c9e3158ce2661df2ad28d7931dd6", nil)) + assert.True(t, IsEmptyCommitID("0000000000000000000000000000000000000000000000000000000000000000", nil)) + assert.False(t, IsEmptyCommitID("0000000000000000000000000000000000000000000000000000000000000000", Sha1ObjectFormat)) + assert.True(t, IsEmptyCommitID("0000000000000000000000000000000000000000000000000000000000000000", Sha256ObjectFormat)) + + assert.False(t, IsEmptyCommitID("1", nil)) + assert.False(t, IsEmptyCommitID("0", nil)) + + assert.False(t, IsEmptyCommitID("010", nil)) + assert.False(t, IsEmptyCommitID("0 0", nil)) +} -- cgit v1.2.3