Files
athens/pkg/errors/errors_test.go
Manu Gupta bb250437da Instrumenting observability with opencensus (#604)
* Initial chanages for observability

* Fix some panics to start testing

* Export tracing properly

* First example of child spans using opencensus

* Add spans to download protocol

* Add url to traces

* Remove opentracing

* Remove gopkg.* files

* Start deprecating opentracing

* Resolve stupid build errors

* Use observability package

* Fix test errors

* Convert buffalo spans to observercontext

* change package name

* defer flush to the end of the app execution

* Change op names to the correct package

* Rename pkg/observability to pkg/observ

* Show traces for the package

* Keep tracing in the earlier way

* Add info from request headers

* Remove whitespace

* Move exporter url to env var

* Add to env file for documentation

* Remove opentracing stuff

* Use stdlib

* Shorten service name

* Add a service name to olympus as well

* Add test to test if there is a recursion or not

* Add Ops Suite

* Move around code

* Make sure the service is not instantiated if the exporter is not found
2018-09-11 10:31:20 -07:00

83 lines
1.7 KiB
Go

package errors
import (
"errors"
"net/http"
"testing"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
//OpTests composes a testsuite to run all the Ops related tests in one group
type OpTests struct {
suite.Suite
}
func TestErrMsg(t *testing.T) {
const op Op = "TestErrMsg"
msg := "test error"
err := E(op, msg)
require.Equal(t, msg, err.Error())
}
func TestErrEmbed(t *testing.T) {
const op Op = "TestErrEmbed"
msg := "test error"
childErr := errors.New(msg)
err := E(op, childErr)
require.Equal(t, err.Error(), childErr.Error())
}
func TestSeverity(t *testing.T) {
const op Op = "TestSeverity"
msg := "test error"
err := E(op, msg)
require.Equal(t, logrus.ErrorLevel, Severity(err))
err = E(op, msg, logrus.WarnLevel)
require.Equal(t, logrus.WarnLevel, Severity(err))
err = E(op, err)
require.Equal(t, logrus.WarnLevel, Severity(err))
err = E(op, err, logrus.InfoLevel)
require.Equal(t, logrus.InfoLevel, Severity(err))
}
func TestKind(t *testing.T) {
const op Op = "TestKind"
msg := "test error"
err := E(op, msg, KindBadRequest)
require.Equal(t, KindBadRequest, Kind(err))
require.Equal(t, http.StatusText(http.StatusBadRequest), KindText(err))
}
func TestOps(t *testing.T) {
suite.Run(t, new(OpTests))
}
func (op *OpTests) TestOps() {
const (
op1 Op = "TestOps.op1"
op2 Op = "TestOps.op2"
op3 Op = "TestOps.op3"
)
err1 := E(op1, "op 1")
err2 := E(op2, err1)
err3 := E(op3, err2)
require.ElementsMatch(op.T(), []Op{op1, op2, op3}, Ops(err3.(Error)))
}
func (op *OpTests) SetupTest() {}
func (op *OpTests) TestString() {
const op1 Op = "testOps.op1"
require.Equal(op.T(), op1.String(), "testOps.op1")
}