github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/git/utils_test.go (about)

     1  // Copyright 2023 The GitBundle Inc. All rights reserved.
     2  // Copyright 2017 The Gitea Authors. All rights reserved.
     3  // Use of this source code is governed by a MIT-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package git
     7  
     8  import (
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/assert"
    12  )
    13  
    14  func TestRefEndName(t *testing.T) {
    15  	// Test branch names (with and without slash).
    16  	assert.Equal(t, "foo", RefEndName("refs/heads/foo"))
    17  	assert.Equal(t, "feature/foo", RefEndName("refs/heads/feature/foo"))
    18  
    19  	// Test tag names (with and without slash).
    20  	assert.Equal(t, "foo", RefEndName("refs/tags/foo"))
    21  	assert.Equal(t, "release/foo", RefEndName("refs/tags/release/foo"))
    22  
    23  	// Test commit hashes.
    24  	assert.Equal(t, "c0ffee", RefEndName("c0ffee"))
    25  }
    26  
    27  func TestRefURL(t *testing.T) {
    28  	repoURL := "/user/repo"
    29  	assert.Equal(t, repoURL+"/src/branch/foo", RefURL(repoURL, "refs/heads/foo"))
    30  	assert.Equal(t, repoURL+"/src/tag/foo", RefURL(repoURL, "refs/tags/foo"))
    31  	assert.Equal(t, repoURL+"/src/commit/c0ffee", RefURL(repoURL, "c0ffee"))
    32  }