-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathstring_test.go
81 lines (65 loc) · 2.29 KB
/
string_test.go
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package scrubbers
import (
"context"
"testing"
. "github.com/go-playground/assert/v2"
)
// NOTES:
// - Run "go test" to run tests
// - Run "gocov test | gocov report" to report on test converage by file
// - Run "gocov test | gocov annotate -" to report on all code and functions, those ,marked with "MISS" were never called
//
// or
//
// -- may be a good idea to change to output path to somewherelike /tmp
// go test -coverprofile cover.out && go tool cover -html=cover.out -o cover.html
//
func TestEmails(t *testing.T) {
scrub := New()
email := "Dean.Karn@gmail.com"
type Test struct {
Email string `scrub:"emails"`
}
tt := Test{Email: email}
err := scrub.Struct(context.Background(), &tt)
Equal(t, err, nil)
Equal(t, tt.Email, "<<scrubbed::email::sha1::5131512f2d165ca283b055bc6f32bc01dd23121e>>@gmail.com")
err = scrub.Field(context.Background(), &email, "emails")
Equal(t, err, nil)
Equal(t, email, "<<scrubbed::email::sha1::5131512f2d165ca283b055bc6f32bc01dd23121e>>@gmail.com")
var iface interface{}
err = scrub.Field(context.Background(), &iface, "emails")
Equal(t, err, nil)
Equal(t, iface, nil)
iface = "Dean.Karn@gmail.com"
err = scrub.Field(context.Background(), &iface, "emails")
Equal(t, err, nil)
Equal(t, iface, "<<scrubbed::email::sha1::5131512f2d165ca283b055bc6f32bc01dd23121e>>@gmail.com")
}
func TestText(t *testing.T) {
scrub := New()
name := "Joey Bloggs"
type Test struct {
String string `scrub:"text"`
}
tt := Test{String: name}
err := scrub.Struct(context.Background(), &tt)
Equal(t, err, nil)
Equal(t, tt.String, "<<scrubbed::text::sha1::028f74c1850aa1efb33a2e8746c0f4183e1e8e30>>")
err = scrub.Field(context.Background(), &name, "text")
Equal(t, err, nil)
Equal(t, name, "<<scrubbed::text::sha1::028f74c1850aa1efb33a2e8746c0f4183e1e8e30>>")
var iface interface{}
err = scrub.Field(context.Background(), &iface, "text")
Equal(t, err, nil)
Equal(t, iface, nil)
iface = "Joey Bloggs"
err = scrub.Field(context.Background(), &iface, "text")
Equal(t, err, nil)
Equal(t, iface, "<<scrubbed::text::sha1::028f74c1850aa1efb33a2e8746c0f4183e1e8e30>>")
// testing Text wrapped func
name = "Joey Bloggs"
err = scrub.Field(context.Background(), &name, "name")
Equal(t, err, nil)
Equal(t, name, "<<scrubbed::name::sha1::028f74c1850aa1efb33a2e8746c0f4183e1e8e30>>")
}