github.com/mundipagg/boleto-api@v0.0.0-20230620145841-3f9ec742599f/log/log_test.go (about)

     1  package log
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  type TestParametersOfLogHeaders struct {
    10  	Input    map[string]string
    11  	Expected map[string]string
    12  }
    13  
    14  var headers = []TestParametersOfLogHeaders{
    15  	{
    16  		Input:    map[string]string{"Authorization": "", "ContentType": ""},
    17  		Expected: map[string]string{"Authorization": "[REDACTED]", "ContentType": ""}},
    18  	{
    19  		Input:    map[string]string{"Authorization": "", "ContentType": "", "access_token": ""},
    20  		Expected: map[string]string{"Authorization": "[REDACTED]", "ContentType": "", "access_token": "[REDACTED]"},
    21  	},
    22  	{
    23  		Input:    map[string]string{"ContentType": "", "itau-chave": "", "Date": ""},
    24  		Expected: map[string]string{"ContentType": "", "itau-chave": "[REDACTED]", "Date": ""},
    25  	},
    26  }
    27  
    28  func TestMaskSecretHeaders(t *testing.T) {
    29  	l := CreateLog()
    30  
    31  	for _, v := range headers {
    32  		result := l.maskSecretHeaders(v.Input)
    33  		assert.Equal(t, v.Expected, result)
    34  	}
    35  }