code.gitea.io/gitea@v1.19.3/modules/git/utils_test.go (about) 1 // Copyright 2020 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package git 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestRefEndName(t *testing.T) { 13 // Test branch names (with and without slash). 14 assert.Equal(t, "foo", RefEndName("refs/heads/foo")) 15 assert.Equal(t, "feature/foo", RefEndName("refs/heads/feature/foo")) 16 17 // Test tag names (with and without slash). 18 assert.Equal(t, "foo", RefEndName("refs/tags/foo")) 19 assert.Equal(t, "release/foo", RefEndName("refs/tags/release/foo")) 20 21 // Test commit hashes. 22 assert.Equal(t, "c0ffee", RefEndName("c0ffee")) 23 } 24 25 func TestRefURL(t *testing.T) { 26 repoURL := "/user/repo" 27 assert.Equal(t, repoURL+"/src/branch/foo", RefURL(repoURL, "refs/heads/foo")) 28 assert.Equal(t, repoURL+"/src/tag/foo", RefURL(repoURL, "refs/tags/foo")) 29 assert.Equal(t, repoURL+"/src/commit/c0ffee", RefURL(repoURL, "c0ffee")) 30 }