diff options
author | Daniel Baumann <daniel@debian.org> | 2024-10-18 20:33:49 +0200 |
---|---|---|
committer | Daniel Baumann <daniel@debian.org> | 2024-12-12 23:57:56 +0100 |
commit | e68b9d00a6e05b3a941f63ffb696f91e554ac5ec (patch) | |
tree | 97775d6c13b0f416af55314eb6a89ef792474615 /modules/git/ref_test.go | |
parent | Initial commit. (diff) | |
download | forgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.tar.xz forgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.zip |
Adding upstream version 9.0.3.
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'modules/git/ref_test.go')
-rw-r--r-- | modules/git/ref_test.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/modules/git/ref_test.go b/modules/git/ref_test.go new file mode 100644 index 0000000..58f679b --- /dev/null +++ b/modules/git/ref_test.go @@ -0,0 +1,38 @@ +// Copyright 2020 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package git + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestRefName(t *testing.T) { + // Test branch names (with and without slash). + assert.Equal(t, "foo", RefName("refs/heads/foo").BranchName()) + assert.Equal(t, "feature/foo", RefName("refs/heads/feature/foo").BranchName()) + + // Test tag names (with and without slash). + assert.Equal(t, "foo", RefName("refs/tags/foo").TagName()) + assert.Equal(t, "release/foo", RefName("refs/tags/release/foo").TagName()) + + // Test pull names + assert.Equal(t, "1", RefName("refs/pull/1/head").PullName()) + assert.Equal(t, "my/pull", RefName("refs/pull/my/pull/head").PullName()) + + // Test for branch names + assert.Equal(t, "main", RefName("refs/for/main").ForBranchName()) + assert.Equal(t, "my/branch", RefName("refs/for/my/branch").ForBranchName()) + + // Test commit hashes. + assert.Equal(t, "c0ffee", RefName("c0ffee").ShortName()) +} + +func TestRefURL(t *testing.T) { + repoURL := "/user/repo" + assert.Equal(t, repoURL+"/src/branch/foo", RefURL(repoURL, "refs/heads/foo")) + assert.Equal(t, repoURL+"/src/tag/foo", RefURL(repoURL, "refs/tags/foo")) + assert.Equal(t, repoURL+"/src/commit/c0ffee", RefURL(repoURL, "c0ffee")) +} |