github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/broker/logging_test.go (about)

     1  package broker
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func TestHideSensitiveDataFromContext(t *testing.T) {
    12  	// This test is just a way to show, how the hideSensitiveDataFromContext works
    13  	in := map[string]interface{}{
    14  		"password": "pa2345",
    15  		"username": "johnsmith",
    16  		"subobject": map[string]interface{}{
    17  			"secret": "val",
    18  			"sm_url": "https://sm.url.com",
    19  		},
    20  		"isValid": true,
    21  	}
    22  
    23  	// when
    24  	out := hideSensitiveDataFromContext(in)
    25  
    26  	d, err := json.Marshal(out)
    27  	require.NoError(t, err)
    28  	assert.Equal(t, `{"isValid":true,"password":"*****","subobject":{"secret":"*****","sm_url":"https://sm.url.com"},"username":"*****"}`, string(d))
    29  }