github.com/searKing/golang/go@v1.2.117/database/dsn/dsn_test.go (about)

     1  package dsn_test
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/searKing/golang/go/database/dsn"
     8  )
     9  
    10  func TestMasking(t *testing.T) {
    11  	for k, tc := range []struct {
    12  		dsn       string
    13  		maskedDsn string
    14  	}{
    15  		{dsn: "mysql://foo:bar@tcp(baz:1234)/db?foo=bar", maskedDsn: "mysql://*:*@tcp(baz:1234)/db?foo=bar"},
    16  		{dsn: "mysql://foo@email.com:bar@tcp(baz:1234)/db?foo=bar", maskedDsn: "mysql://*:*@tcp(baz:1234)/db?foo=bar"},
    17  		{dsn: "postgres://foo:bar@baz:1234/db?foo=bar", maskedDsn: "postgres://*:*@baz:1234/db?foo=bar"},
    18  		{dsn: "postgres://foo@email.com:bar@baz:1234/db?foo=bar", maskedDsn: "postgres://*:*@baz:1234/db?foo=bar"},
    19  	} {
    20  		t.Run(fmt.Sprintf("case=%d", k), func(t *testing.T) {
    21  			maskedDsn := dsn.Masking(tc.dsn)
    22  
    23  			if maskedDsn != tc.maskedDsn {
    24  				t.Fatalf("%s, expected %q, got %q", tc.dsn, tc.maskedDsn, maskedDsn)
    25  			}
    26  		})
    27  	}
    28  }