Exemplo n.º 1
0
func wrapErr(err error) error {
	switch err := err.(type) {
	case *MutedError, *UnmutedError:
		return err
	default:
		return &UnmutedError{Err: err, Stack: stack.NewTrace(2)}
	}
}
Exemplo n.º 2
0
func TestNotify(t *testing.T) {
	config := &Config{
		APIKey:       "abcd",
		Endpoint:     "http://localhost:5051/",
		ReleaseStage: "staging",
		AppVersion:   "1.0",
		Hostname:     "",
	}

	n := notifyHandler{
		PayloadChan: make(chan *payload, 1),
	}

	go http.ListenAndServe(":5051", n)
	time.Sleep(10 * time.Millisecond)

	err := Notify(config, "users/get", "foo.bar", fmt.Errorf("imanerror"), stack.NewTrace(0), make(map[string]string))
	if err != nil {
		t.Fatalf("expected no error, got %v", err)
	}

	p := <-n.PayloadChan

	assert.NotNil(t, p)
	assert.Equal(t, p.APIKey, "abcd")
	assert.Equal(t, p.Notifier.Name, "health")
	assert.Equal(t, len(p.Events), 1)

	evt := p.Events[0]
	assert.Equal(t, evt.Context, "users/get")
	assert.Equal(t, evt.App.ReleaseStage, "staging")
	assert.Equal(t, len(evt.Exceptions), 1)

	ex := evt.Exceptions[0]
	assert.Equal(t, ex.ErrorClass, "foo.bar")
	assert.Equal(t, ex.Message, "imanerror")

	frame := ex.Stacktrace[0]
	assert.True(t, strings.HasSuffix(frame.File, "api_test.go"))
	assert.Equal(t, frame.Method, "github.com/gocraft/health/sinks/bugsnag:TestNotify")

}
Exemplo n.º 3
0
func TestSink(t *testing.T) {
	config := &Config{
		APIKey:       "abcd",
		Endpoint:     "http://localhost:5052/",
		ReleaseStage: "staging",
		AppVersion:   "1.0",
		Hostname:     "",
	}

	s := NewSink(config)
	defer s.ShutdownServer()

	n := notifyHandler{
		PayloadChan: make(chan *payload, 2),
	}

	go http.ListenAndServe(":5052", n)

	err := &health.UnmutedError{Err: fmt.Errorf("err str"), Stack: stack.NewTrace(2)}
	s.EmitEventErr("thejob", "theevent", err, nil)

	p := <-n.PayloadChan
	evt := p.Events[0]
	assert.Equal(t, evt.Context, "thejob")

	ex := evt.Exceptions[0]
	assert.Equal(t, ex.ErrorClass, "theevent")
	assert.Equal(t, ex.Message, "err str")

	err.Emitted = true
	s.EmitEventErr("thejob", "theevent2", err, nil)

	time.Sleep(1 * time.Millisecond)

	select {
	case <-n.PayloadChan:
		t.Errorf("did not expect payload")
	default:
		// yay
	}
}