mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-30 10:58:27 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			41 lines
		
	
	
		
			858 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			858 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright 2025 The Gitea Authors. All rights reserved.
 | |
| // SPDX-License-Identifier: MIT
 | |
| 
 | |
| package attribute
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| 	"os"
 | |
| 	"testing"
 | |
| 
 | |
| 	"code.gitea.io/gitea/modules/git"
 | |
| 	"code.gitea.io/gitea/modules/setting"
 | |
| 	"code.gitea.io/gitea/modules/util"
 | |
| )
 | |
| 
 | |
| func testRun(m *testing.M) error {
 | |
| 	gitHomePath, err := os.MkdirTemp(os.TempDir(), "git-home")
 | |
| 	if err != nil {
 | |
| 		return fmt.Errorf("unable to create temp dir: %w", err)
 | |
| 	}
 | |
| 	defer util.RemoveAll(gitHomePath)
 | |
| 	setting.Git.HomePath = gitHomePath
 | |
| 
 | |
| 	if err = git.InitFull(); err != nil {
 | |
| 		return fmt.Errorf("failed to call Init: %w", err)
 | |
| 	}
 | |
| 
 | |
| 	exitCode := m.Run()
 | |
| 	if exitCode != 0 {
 | |
| 		return fmt.Errorf("run test failed, ExitCode=%d", exitCode)
 | |
| 	}
 | |
| 	return nil
 | |
| }
 | |
| 
 | |
| func TestMain(m *testing.M) {
 | |
| 	if err := testRun(m); err != nil {
 | |
| 		_, _ = fmt.Fprintf(os.Stderr, "Test failed: %v", err)
 | |
| 		os.Exit(1)
 | |
| 	}
 | |
| }
 |