code.gitea.io/gitea@v1.22.3/modules/git/ref_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 TestRefName(t *testing.T) {
    13  	// Test branch names (with and without slash).
    14  	assert.Equal(t, "foo", RefName("refs/heads/foo").BranchName())
    15  	assert.Equal(t, "feature/foo", RefName("refs/heads/feature/foo").BranchName())
    16  
    17  	// Test tag names (with and without slash).
    18  	assert.Equal(t, "foo", RefName("refs/tags/foo").TagName())
    19  	assert.Equal(t, "release/foo", RefName("refs/tags/release/foo").TagName())
    20  
    21  	// Test pull names
    22  	assert.Equal(t, "1", RefName("refs/pull/1/head").PullName())
    23  	assert.Equal(t, "my/pull", RefName("refs/pull/my/pull/head").PullName())
    24  
    25  	// Test for branch names
    26  	assert.Equal(t, "main", RefName("refs/for/main").ForBranchName())
    27  	assert.Equal(t, "my/branch", RefName("refs/for/my/branch").ForBranchName())
    28  
    29  	// Test commit hashes.
    30  	assert.Equal(t, "c0ffee", RefName("c0ffee").ShortName())
    31  }
    32  
    33  func TestRefURL(t *testing.T) {
    34  	repoURL := "/user/repo"
    35  	assert.Equal(t, repoURL+"/src/branch/foo", RefURL(repoURL, "refs/heads/foo"))
    36  	assert.Equal(t, repoURL+"/src/tag/foo", RefURL(repoURL, "refs/tags/foo"))
    37  	assert.Equal(t, repoURL+"/src/commit/c0ffee", RefURL(repoURL, "c0ffee"))
    38  }