github.com/grafana/synthetic-monitoring-agent@v0.64.2/cmd/synthetic-monitoring-agent/secret_test.go (about) 1 package main 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestSecret(t *testing.T) { 11 testcases := map[string]struct { 12 input string 13 }{ 14 "empty": {input: ""}, 15 "secret": {input: "secret"}, 16 "blank": {input: " "}, 17 } 18 19 for name, tc := range testcases { 20 t.Run(name, func(t *testing.T) { 21 var s Secret 22 23 require.NoError(t, s.Set(tc.input)) 24 25 require.Equal(t, tc.input, string(s)) 26 27 require.Equal(t, "<redacted>", s.String()) 28 29 text, err := s.MarshalText() 30 require.NoError(t, err) 31 require.Equal(t, []byte("<redacted>"), text) 32 33 buf, err := json.Marshal(s) 34 require.NoError(t, err) 35 require.Equal(t, []byte(`"\u003credacted\u003e"`), buf) 36 }) 37 } 38 }