mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-27 00:23:41 +09:00 
			
		
		
		
	* Fix #35144 * Fix #35117 * Fix https://github.com/go-gitea/gitea/issues/35054#issuecomment-3131793977 * Fix #35136
		
			
				
	
	
		
			41 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright 2024 The Gitea Authors. All rights reserved.
 | |
| // SPDX-License-Identifier: MIT
 | |
| 
 | |
| package git
 | |
| 
 | |
| import (
 | |
| 	"testing"
 | |
| 
 | |
| 	"github.com/stretchr/testify/assert"
 | |
| )
 | |
| 
 | |
| func TestCommitSubmoduleLink(t *testing.T) {
 | |
| 	assert.Nil(t, (*CommitSubmoduleFile)(nil).SubmoduleWebLinkTree(t.Context()))
 | |
| 	assert.Nil(t, (*CommitSubmoduleFile)(nil).SubmoduleWebLinkCompare(t.Context(), "", ""))
 | |
| 	assert.Nil(t, (&CommitSubmoduleFile{}).SubmoduleWebLinkTree(t.Context()))
 | |
| 	assert.Nil(t, (&CommitSubmoduleFile{}).SubmoduleWebLinkCompare(t.Context(), "", ""))
 | |
| 
 | |
| 	t.Run("GitHubRepo", func(t *testing.T) {
 | |
| 		sf := NewCommitSubmoduleFile("/any/repo-link", "full-path", "git@github.com:user/repo.git", "aaaa")
 | |
| 		wl := sf.SubmoduleWebLinkTree(t.Context())
 | |
| 		assert.Equal(t, "https://github.com/user/repo", wl.RepoWebLink)
 | |
| 		assert.Equal(t, "https://github.com/user/repo/tree/aaaa", wl.CommitWebLink)
 | |
| 
 | |
| 		wl = sf.SubmoduleWebLinkCompare(t.Context(), "1111", "2222")
 | |
| 		assert.Equal(t, "https://github.com/user/repo", wl.RepoWebLink)
 | |
| 		assert.Equal(t, "https://github.com/user/repo/compare/1111...2222", wl.CommitWebLink)
 | |
| 	})
 | |
| 
 | |
| 	t.Run("RelativePath", func(t *testing.T) {
 | |
| 		sf := NewCommitSubmoduleFile("/subpath/any/repo-home-link", "full-path", "../../user/repo", "aaaa")
 | |
| 		wl := sf.SubmoduleWebLinkTree(t.Context())
 | |
| 		assert.Equal(t, "/subpath/user/repo", wl.RepoWebLink)
 | |
| 		assert.Equal(t, "/subpath/user/repo/tree/aaaa", wl.CommitWebLink)
 | |
| 
 | |
| 		sf = NewCommitSubmoduleFile("/subpath/any/repo-home-link", "dir/submodule", "../../user/repo", "aaaa")
 | |
| 		wl = sf.SubmoduleWebLinkCompare(t.Context(), "1111", "2222")
 | |
| 		assert.Equal(t, "/subpath/user/repo", wl.RepoWebLink)
 | |
| 		assert.Equal(t, "/subpath/user/repo/compare/1111...2222", wl.CommitWebLink)
 | |
| 	})
 | |
| }
 |