mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	upgrade to use testfixtures v3 (#11904)
* upgrade to use testfixtures v3 * simplify logic * make vendor * update per @lunny * Update templates/repo/empty.tmpl * Update templates/repo/empty.tmpl Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
		
							
								
								
									
										71
									
								
								vendor/github.com/go-testfixtures/testfixtures/v3/helper.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								vendor/github.com/go-testfixtures/testfixtures/v3/helper.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,71 @@
 | 
			
		||||
package testfixtures
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"database/sql"
 | 
			
		||||
	"fmt"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	paramTypeDollar = iota + 1
 | 
			
		||||
	paramTypeQuestion
 | 
			
		||||
	paramTypeAtSign
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type loadFunction func(tx *sql.Tx) error
 | 
			
		||||
 | 
			
		||||
type helper interface {
 | 
			
		||||
	init(*sql.DB) error
 | 
			
		||||
	disableReferentialIntegrity(*sql.DB, loadFunction) error
 | 
			
		||||
	paramType() int
 | 
			
		||||
	databaseName(queryable) (string, error)
 | 
			
		||||
	tableNames(queryable) ([]string, error)
 | 
			
		||||
	isTableModified(queryable, string) (bool, error)
 | 
			
		||||
	afterLoad(queryable) error
 | 
			
		||||
	quoteKeyword(string) string
 | 
			
		||||
	whileInsertOnTable(*sql.Tx, string, func() error) error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type queryable interface {
 | 
			
		||||
	Exec(string, ...interface{}) (sql.Result, error)
 | 
			
		||||
	Query(string, ...interface{}) (*sql.Rows, error)
 | 
			
		||||
	QueryRow(string, ...interface{}) *sql.Row
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// batchSplitter is an interface with method which returns byte slice for
 | 
			
		||||
// splitting SQL batches. This need to split sql statements and run its
 | 
			
		||||
// separately.
 | 
			
		||||
//
 | 
			
		||||
// For Microsoft SQL Server batch splitter is "GO". For details see
 | 
			
		||||
// https://docs.microsoft.com/en-us/sql/t-sql/language-elements/sql-server-utilities-statements-go
 | 
			
		||||
type batchSplitter interface {
 | 
			
		||||
	splitter() []byte
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	_ helper = &mySQL{}
 | 
			
		||||
	_ helper = &postgreSQL{}
 | 
			
		||||
	_ helper = &sqlite{}
 | 
			
		||||
	_ helper = &sqlserver{}
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type baseHelper struct{}
 | 
			
		||||
 | 
			
		||||
func (baseHelper) init(_ *sql.DB) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (baseHelper) quoteKeyword(str string) string {
 | 
			
		||||
	return fmt.Sprintf(`"%s"`, str)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (baseHelper) whileInsertOnTable(_ *sql.Tx, _ string, fn func() error) error {
 | 
			
		||||
	return fn()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (baseHelper) isTableModified(_ queryable, _ string) (bool, error) {
 | 
			
		||||
	return true, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (baseHelper) afterLoad(_ queryable) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user