-
Notifications
You must be signed in to change notification settings - Fork 1
/
masking_test.go
37 lines (27 loc) · 868 Bytes
/
masking_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
package pii_test
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/ThreeDotsLabs/pii"
)
func TestMaskingAnonymizer(t *testing.T) {
ctx := context.Background()
a := pii.NewStructAnonymizer[string, testStruct](pii.MaskingAnonymizer[string]{})
s := testStruct{
FirstName: "John",
LastName: "Doe",
Company: "ThreeDotsLabs",
}
anonymized, err := a.Anonymize(ctx, "***", s)
require.NoError(t, err)
assert.Equal(t, "***", anonymized.FirstName)
assert.Equal(t, "***", anonymized.LastName)
assert.Equal(t, "ThreeDotsLabs", anonymized.Company)
deanonymized, err := a.Deanonymize(ctx, "", anonymized)
require.NoError(t, err)
assert.Equal(t, "***", deanonymized.FirstName)
assert.Equal(t, "***", deanonymized.LastName)
assert.Equal(t, "ThreeDotsLabs", deanonymized.Company)
}