-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add test without header and without match
- Loading branch information
1 parent
12fabf0
commit 304697d
Showing
2 changed files
with
54 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,54 +19,51 @@ package findincsv | |
|
||
import ( | ||
"testing" | ||
tmpl "text/template" | ||
|
||
"github.com/cgi-fr/pimo/pkg/model" | ||
"github.com/cgi-fr/pimo/pkg/templatemask" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFactoryShouldCreateAMaskWith2Templates(t *testing.T) { | ||
func TestFactoryShouldCreateAMaskAndFindMatchSimple(t *testing.T) { | ||
exactMatch := model.ExactMatchType{ | ||
CSV: "{{.last_name}}+123", | ||
Entry: "{{.nom}}+456", | ||
Entry: "{{.nom}}+123", | ||
} | ||
config := model.FindInCSVType{ | ||
URI: "file://../../test/persons.csv", | ||
ExactMatch: exactMatch, | ||
Expected: "only-one", | ||
Header: false, | ||
Header: true, | ||
TrimSpace: true, | ||
} | ||
maskingConfig := model.Masking{Mask: model.MaskType{FindInCSV: config}} | ||
factoryConfig := model.MaskFactoryConfiguration{Masking: maskingConfig, Seed: 0} | ||
tempMaskCsv, err := templatemask.NewMask(factoryConfig.Masking.Mask.FindInCSV.ExactMatch.CSV, tmpl.FuncMap{}, 0, "") | ||
if err != nil { | ||
assert.Fail(t, err.Error()) | ||
} | ||
tempMaskEntry, err := templatemask.NewMask(factoryConfig.Masking.Mask.FindInCSV.ExactMatch.Entry, tmpl.FuncMap{}, 0, "") | ||
if err != nil { | ||
assert.Fail(t, err.Error()) | ||
} | ||
data := model.NewDictionary().With("nom", "Jean").With("last_name", "Bonbeur").With("mail", "[email protected]").Pack() | ||
resultCsv, err := tempMaskCsv.Mask("[email protected]", data) | ||
resultEntry, err := tempMaskEntry.Mask("[email protected]", data) | ||
assert.Equal(t, nil, err, "error should be nil") | ||
waitedCsv := "Bonbeur+123" | ||
assert.Equal(t, waitedCsv, resultCsv, "Should create the right mail") | ||
waitedEntry := "Jean+456" | ||
assert.Equal(t, waitedEntry, resultEntry, "Should create the right mail") | ||
mask, present, err := Factory(factoryConfig) | ||
assert.Nil(t, err, "error should be nil") | ||
assert.True(t, present, "should be true") | ||
data := model.NewDictionary().With("nom", "Vidal").With("info_personne", "").Pack() | ||
masked, err := mask.Mask("info_personne", data) | ||
|
||
assert.Equal(t, | ||
model.NewDictionary(). | ||
With("last_name", "Vidal"). | ||
With("email", "[email protected]"). | ||
With("first_name", "Luce").Unordered(), | ||
masked.(model.Dictionary).Unordered(), | ||
) | ||
assert.Nil(t, err, "error should be nil") | ||
} | ||
|
||
func TestFactoryShouldCreateAMaskAndFindMatchSimple(t *testing.T) { | ||
func TestFactoryShouldCreateAMaskAndFindMatchWithoutHeader(t *testing.T) { | ||
exactMatch := model.ExactMatchType{ | ||
CSV: "{{.last_name}}+123", | ||
CSV: "{{index . \"1\"}}+123", | ||
Entry: "{{.nom}}+123", | ||
} | ||
config := model.FindInCSVType{ | ||
URI: "file://../../test/persons.csv", | ||
ExactMatch: exactMatch, | ||
Expected: "only-one", | ||
Header: true, | ||
Header: false, | ||
TrimSpace: true, | ||
} | ||
maskingConfig := model.Masking{Mask: model.MaskType{FindInCSV: config}} | ||
|
@@ -76,13 +73,37 @@ func TestFactoryShouldCreateAMaskAndFindMatchSimple(t *testing.T) { | |
assert.True(t, present, "should be true") | ||
data := model.NewDictionary().With("nom", "Vidal").With("info_personne", "").Pack() | ||
masked, err := mask.Mask("info_personne", data) | ||
assert.Nil(t, err, "error should be nil") | ||
|
||
assert.Equal(t, | ||
model.NewDictionary(). | ||
With("last_name", "Vidal"). | ||
With("email", "[email protected]"). | ||
With("first_name", "Luce").Unordered(), | ||
With("0", "Luce"). | ||
With("1", "Vidal"). | ||
With("2", "[email protected]").Unordered(), | ||
masked.(model.Dictionary).Unordered(), | ||
) | ||
} | ||
|
||
func TestFactoryShouldCreateAMaskAndDontFindMatch(t *testing.T) { | ||
exactMatch := model.ExactMatchType{ | ||
CSV: "{{.last_name}}+123", | ||
Entry: "{{.nom}}+123", | ||
} | ||
config := model.FindInCSVType{ | ||
URI: "file://../../test/persons.csv", | ||
ExactMatch: exactMatch, | ||
Expected: "only-one", | ||
Header: false, | ||
TrimSpace: true, | ||
} | ||
maskingConfig := model.Masking{Mask: model.MaskType{FindInCSV: config}} | ||
factoryConfig := model.MaskFactoryConfiguration{Masking: maskingConfig, Seed: 0} | ||
mask, present, err := Factory(factoryConfig) | ||
assert.Nil(t, err, "error should be nil") | ||
assert.True(t, present, "should be true") | ||
data := model.NewDictionary().With("nom", "Hello").With("info_personne", "").Pack() | ||
masked, err := mask.Mask("info_personne", data) | ||
assert.Nil(t, err, "error should be nil") | ||
|
||
assert.Equal(t, []model.Entry{}, masked) | ||
} |