mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-11-04 05:25:15 +01:00 
			
		
		
		
	1. fix incorrect tests, for example: BeanExists doesn't do assert and shouldn't be used 2. remove unnecessary test functions 3. introduce DumpQueryResult to help to see the database rows during test (at least I need it) ``` ====== DumpQueryResult: SELECT * FROM action_runner_token ====== - # row[0] id: 1 token: xeiWBL5kuTYxGPynHCqQdoeYmJAeG3IzGXCYTrDX owner_id: 0 ... ```
		
			
				
	
	
		
			41 lines
		
	
	
		
			808 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			808 B
		
	
	
	
		
			Go
		
	
	
	
	
	
// Copyright 2021 The Gitea Authors. All rights reserved.
 | 
						|
// SPDX-License-Identifier: MIT
 | 
						|
 | 
						|
package unittest
 | 
						|
 | 
						|
import (
 | 
						|
	"fmt"
 | 
						|
	"reflect"
 | 
						|
)
 | 
						|
 | 
						|
func fieldByName(v reflect.Value, field string) reflect.Value {
 | 
						|
	if v.Kind() == reflect.Ptr {
 | 
						|
		v = v.Elem()
 | 
						|
	}
 | 
						|
	f := v.FieldByName(field)
 | 
						|
	if !f.IsValid() {
 | 
						|
		panic(fmt.Errorf("can not read %s for %v", field, v))
 | 
						|
	}
 | 
						|
	return f
 | 
						|
}
 | 
						|
 | 
						|
type reflectionValue struct {
 | 
						|
	v reflect.Value
 | 
						|
}
 | 
						|
 | 
						|
func reflectionWrap(v any) *reflectionValue {
 | 
						|
	return &reflectionValue{v: reflect.ValueOf(v)}
 | 
						|
}
 | 
						|
 | 
						|
func (rv *reflectionValue) int(field string) int {
 | 
						|
	return int(fieldByName(rv.v, field).Int())
 | 
						|
}
 | 
						|
 | 
						|
func (rv *reflectionValue) str(field string) string {
 | 
						|
	return fieldByName(rv.v, field).String()
 | 
						|
}
 | 
						|
 | 
						|
func (rv *reflectionValue) bool(field string) bool {
 | 
						|
	return fieldByName(rv.v, field).Bool()
 | 
						|
}
 |