mirror of
https://github.com/slackhq/nebula.git
synced 2025-12-06 02:30:57 -08:00
Combine ca, cert, and key handling (#952)
This commit is contained in:
parent
223cc6e660
commit
5a131b2975
17 changed files with 381 additions and 294 deletions
|
|
@ -2,6 +2,7 @@ package util
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
|
@ -67,3 +68,44 @@ func TestContextualError_Log(t *testing.T) {
|
|||
e.Log(l)
|
||||
assert.Equal(t, []string{"level=error error=error\n"}, tl.Logs)
|
||||
}
|
||||
|
||||
func TestLogWithContextIfNeeded(t *testing.T) {
|
||||
l := logrus.New()
|
||||
l.Formatter = &logrus.TextFormatter{
|
||||
DisableTimestamp: true,
|
||||
DisableColors: true,
|
||||
}
|
||||
|
||||
tl := NewTestLogWriter()
|
||||
l.Out = tl
|
||||
|
||||
// Test ignoring fallback context
|
||||
tl.Reset()
|
||||
e := NewContextualError("test message", m{"field": "1"}, errors.New("error"))
|
||||
LogWithContextIfNeeded("This should get thrown away", e, l)
|
||||
assert.Equal(t, []string{"level=error msg=\"test message\" error=error field=1\n"}, tl.Logs)
|
||||
|
||||
// Test using fallback context
|
||||
tl.Reset()
|
||||
err := fmt.Errorf("this is a normal error")
|
||||
LogWithContextIfNeeded("Fallback context woo", err, l)
|
||||
assert.Equal(t, []string{"level=error msg=\"Fallback context woo\" error=\"this is a normal error\"\n"}, tl.Logs)
|
||||
}
|
||||
|
||||
func TestContextualizeIfNeeded(t *testing.T) {
|
||||
// Test ignoring fallback context
|
||||
e := NewContextualError("test message", m{"field": "1"}, errors.New("error"))
|
||||
assert.Same(t, e, ContextualizeIfNeeded("should be ignored", e))
|
||||
|
||||
// Test using fallback context
|
||||
err := fmt.Errorf("this is a normal error")
|
||||
cErr := ContextualizeIfNeeded("Fallback context woo", err)
|
||||
|
||||
switch v := cErr.(type) {
|
||||
case *ContextualError:
|
||||
assert.Equal(t, err, v.RealError)
|
||||
default:
|
||||
t.Error("Error was not wrapped")
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue