mirror of
https://github.com/restic/restic.git
synced 2026-07-08 00:05:09 +00:00
Add last integration tests, remove testsuite
This commit is contained in:
@@ -18,7 +18,6 @@ import (
|
||||
var opts struct {
|
||||
logger *log.Logger
|
||||
tags map[string]bool
|
||||
breaks map[string]bool
|
||||
m sync.Mutex
|
||||
}
|
||||
|
||||
@@ -29,7 +28,6 @@ var _ = initDebug()
|
||||
func initDebug() bool {
|
||||
initDebugLogger()
|
||||
initDebugTags()
|
||||
initDebugBreaks()
|
||||
|
||||
fmt.Fprintf(os.Stderr, "debug enabled\n")
|
||||
|
||||
@@ -105,25 +103,6 @@ func initDebugTags() {
|
||||
fmt.Fprintf(os.Stderr, "debug log enabled for: %v\n", tags)
|
||||
}
|
||||
|
||||
func initDebugBreaks() {
|
||||
opts.breaks = make(map[string]bool)
|
||||
|
||||
env := os.Getenv("DEBUG_BREAK")
|
||||
if len(env) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
breaks := []string{}
|
||||
|
||||
for _, tag := range strings.Split(env, ",") {
|
||||
t := strings.TrimSpace(tag)
|
||||
opts.breaks[t] = true
|
||||
breaks = append(breaks, t)
|
||||
}
|
||||
|
||||
fmt.Fprintf(os.Stderr, "debug breaks enabled for: %v\n", breaks)
|
||||
}
|
||||
|
||||
// taken from https://github.com/VividCortex/trace
|
||||
func goroutineNum() int {
|
||||
b := make([]byte, 20)
|
||||
@@ -194,38 +173,3 @@ func Log(tag string, f string, args ...interface{}) {
|
||||
dbgprint()
|
||||
}
|
||||
}
|
||||
|
||||
// Break stops the program if the debug tag is active and the string in tag is
|
||||
// contained in the DEBUG_BREAK environment variable.
|
||||
func Break(tag string) {
|
||||
// check if breaking is enabled
|
||||
if v, ok := opts.breaks[tag]; !ok || !v {
|
||||
return
|
||||
}
|
||||
|
||||
_, file, line, _ := runtime.Caller(1)
|
||||
Log("break", "stopping process %d at %s (%v:%v)\n", os.Getpid(), tag, file, line)
|
||||
p, err := os.FindProcess(os.Getpid())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = p.Signal(syscall.SIGSTOP)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// BreakIf stops the program if the debug tag is active and the string in tag
|
||||
// is contained in the DEBUG_BREAK environment variable and the return value of
|
||||
// fn is true.
|
||||
func BreakIf(tag string, fn func() bool) {
|
||||
// check if breaking is enabled
|
||||
if v, ok := opts.breaks[tag]; !ok || !v {
|
||||
return
|
||||
}
|
||||
|
||||
if fn() {
|
||||
Break(tag)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,3 @@
|
||||
package debug
|
||||
|
||||
func Log(tag string, fmt string, args ...interface{}) {}
|
||||
|
||||
func Break(string) {}
|
||||
|
||||
func BreakIf(string, func() bool) {}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// +build !release
|
||||
|
||||
package debug
|
||||
|
||||
var (
|
||||
hooks map[string]func(interface{})
|
||||
)
|
||||
|
||||
func init() {
|
||||
hooks = make(map[string]func(interface{}))
|
||||
}
|
||||
|
||||
func Hook(name string, f func(interface{})) {
|
||||
hooks[name] = f
|
||||
}
|
||||
|
||||
func RunHook(name string, context interface{}) {
|
||||
f, ok := hooks[name]
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
f(context)
|
||||
}
|
||||
|
||||
func RemoveHook(name string) {
|
||||
delete(hooks, name)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// +build release
|
||||
|
||||
package debug
|
||||
|
||||
func Hook(name string, f func(interface{})) {}
|
||||
|
||||
func RunHook(name string, context interface{}) {}
|
||||
|
||||
func RemoveHook(name string) {}
|
||||
Reference in New Issue
Block a user