Exemple #1
0
func TestNewContextErrorGeneric(t *testing.T) {
	sklog.SetContextErrorFunc(ctxpq.NewContextErrorGeneric)

	b := bytes.NewBuffer(nil)
	l := log.NewJSONLogger(b)

	for _, e := range pqErrors {
		sklog.Error(l, e)

		assertPqError(t, b, e)
		b.Reset()
	}

	for _, e := range genericErrors {
		sklog.Error(l, e)

		assertGenericError(t, b, e)
		b.Reset()
	}
}
Exemple #2
0
func TestNewContextGeneric(t *testing.T) {
	b := bytes.NewBuffer(nil)
	l := log.NewJSONLogger(b)

	sklog.SetContextErrorFunc(ctxjson.NewContextError)

	for name, data := range successTestData {
		err := ctxstd.NewContextErrorGeneric(l, data.error).Log("key", "value")
		if assert.NoError(t, err) {
			got := b.String()

			for _, key := range data.keys {
				assert.Contains(t, got, key, name+" does not contain key: "+key)
			}

			for _, value := range data.values {
				assert.Contains(t, got, value, name+" does not contain value: "+value)
			}
		}

		b.Reset()
	}
}