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