1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
//go:build !integration
// +build !integration
package log
import (
"bytes"
"testing"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)
func TestSecretsCleanupHook(t *testing.T) {
tests := []struct {
name string
message string
expected string
}{
{
name: "With Secrets",
message: "Get http://localhost/?id=123&X-Amz-Signature=abcd1234&private_token=abcd1234",
expected: "Get http://localhost/?id=123&X-Amz-Signature=[FILTERED]&private_token=[FILTERED]",
},
{
name: "No Secrets",
message: "Fatal: Get http://localhost/?id=123",
expected: "Fatal: Get http://localhost/?id=123",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
buffer := &bytes.Buffer{}
logger := logrus.New()
logger.Out = buffer
AddSecretsCleanupLogHook(logger)
logger.Errorln(test.message)
assert.Contains(t, buffer.String(), test.expected)
})
}
}
|