-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecret_test.go
More file actions
62 lines (56 loc) · 1.28 KB
/
secret_test.go
File metadata and controls
62 lines (56 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package config_test
import (
"encoding/json"
"encoding/xml"
"fmt"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
. "go.octolab.org/toolkit/config"
)
func TestSecret(t *testing.T) {
type password struct {
XMLName struct{} `json:"-" xml:"password" yaml:"-"`
Value Secret `json:"password" xml:"value,attr" yaml:"password"`
}
secret := password{Value: "secret"}
tests := map[string]struct {
marshal func(password) ([]byte, error)
}{
"print by `%#v`": {
func(pass password) ([]byte, error) {
str := fmt.Sprintf("%#v", pass)
return []byte(str), nil
},
},
"print by `%s`": {
func(pass password) ([]byte, error) {
str := fmt.Sprintf("%s", pass.Value) //nolint:gosimple
return []byte(str), nil
},
},
"json marshal": {
func(pass password) ([]byte, error) {
return json.Marshal(pass)
},
},
"xml marshal": {
func(pass password) ([]byte, error) {
return xml.Marshal(pass)
},
},
"yaml marshal": {
func(pass password) ([]byte, error) {
return yaml.Marshal(pass)
},
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
raw, err := test.marshal(secret)
assert.NoError(t, err)
assert.False(t, strings.Contains(string(raw), string(secret.Value)))
})
}
}