Beispiel #1
0
func TestUnderlying(t *testing.T) {
	e1 := errors.New("")
	e2 := stackerr.Wrap(e1)
	errs := stackerr.Underlying(e2)
	if len(errs) != 2 || errs[0] != e2 || errs[1] != e1 {
		t.Fatal("failed Underlying")
	}
}
Beispiel #2
0
func TestWrap(t *testing.T) {
	const errStr = "foo bar baz"
	e := stackerr.Wrap(errors.New(errStr))
	matches := []string{
		errStr,
		"stackerr_test.go:36 +TestWrap$",
	}
	match(t, e.Error(), matches)
}
Beispiel #3
0
func watch() error {
	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		return stackerr.Wrap(err)
	}
	defer watcher.Close()

	argv0, err := exec.LookPath(os.Args[0])
	if err != nil {
		return stackerr.Wrap(err)
	}

	debug("reloader:", argv0)
	if err := watcher.Add(argv0); err != nil {
		return stackerr.Wrap(err)
	}

	var doit <-chan time.Time
	for {
		select {
		case <-doit:
			log.Println("Restarting", argv0)
			if err := syscall.Exec(argv0, os.Args, os.Environ()); err != nil {
				return stackerr.Wrap(err)
			}
		case event := <-watcher.Events:
			debug("watcher.Event:", event)
			doit = time.After(500 * time.Millisecond)
			if err := watcher.Add(event.Name); err != nil {
				return stackerr.Wrap(err)
			}
		case err := <-watcher.Errors:
			debug("watcher.Error:", err)
		}
	}
}