add tests
This commit is contained in:
parent
2db8cc1087
commit
2081937a24
30
app/app_test.go
Normal file
30
app/app_test.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"gitnet.fr/deblan/database-anonymizer/config"
|
||||
"gitnet.fr/deblan/database-anonymizer/faker"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func GetApp() App {
|
||||
return App{
|
||||
FakeManager: faker.NewFakeManager(),
|
||||
DbConfig: config.DatabaseConfig{Type: "mysql", Dsn: "mysql://foo:bar@tests"},
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppCreateSelectQuery(t *testing.T) {
|
||||
c := config.SchemaConfigAction{Table: "foo"}
|
||||
app := GetApp()
|
||||
|
||||
if app.CreateSelectQuery(c) != "SELECT * FROM `foo`" {
|
||||
t.Fatalf("TestAppCreateSelectQuery: empty configured query check failed")
|
||||
}
|
||||
|
||||
c = config.SchemaConfigAction{Table: "foo", Query: "query"}
|
||||
|
||||
if app.CreateSelectQuery(c) != "query" {
|
||||
t.Fatalf("TestAppCreateSelectQuery: configured query check failed")
|
||||
}
|
||||
}
|
88
data/data_test.go
Normal file
88
data/data_test.go
Normal file
|
@ -0,0 +1,88 @@
|
|||
package data
|
||||
|
||||
import (
|
||||
"gitnet.fr/deblan/database-anonymizer/faker"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDataFroms(t *testing.T) {
|
||||
d := Data{}
|
||||
|
||||
var varInt64 int64
|
||||
varInt64 = 42
|
||||
d.FromInt64(varInt64)
|
||||
if d.Value != "42" {
|
||||
t.Fatalf("TestDataFroms: FromInt64 check failed")
|
||||
}
|
||||
|
||||
v := []byte{'A', 'B', 'C'}
|
||||
|
||||
d.FromByte(v)
|
||||
|
||||
if d.Value != "ABC" {
|
||||
t.Fatalf("TestDataFroms: FromByte check failed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDataIsTwigExpression(t *testing.T) {
|
||||
d := Data{Faker: "foo"}
|
||||
if d.IsTwigExpression() {
|
||||
t.Fatalf("IsTwigExpression: IsTwigExpression check failed")
|
||||
}
|
||||
|
||||
d = Data{Faker: "foo {{"}
|
||||
if !d.IsTwigExpression() {
|
||||
t.Fatalf("IsTwigExpression: IsTwigExpression check failed")
|
||||
}
|
||||
|
||||
d = Data{Faker: "}}"}
|
||||
if !d.IsTwigExpression() {
|
||||
t.Fatalf("IsTwigExpression: IsTwigExpression check failed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDataUpdate(t *testing.T) {
|
||||
row := make(map[string]Data)
|
||||
row["bar"] = Data{Value: "bar_value"}
|
||||
manager := faker.NewFakeManager()
|
||||
|
||||
d := Data{Faker: "", Value: "foo"}
|
||||
if d.IsUpdated {
|
||||
t.Fatalf("TestDataUpdate: IsUpdated check failed")
|
||||
}
|
||||
|
||||
d.Update(row, manager)
|
||||
if d.IsUpdated {
|
||||
t.Fatalf("TestDataUpdate: IsUpdated check failed")
|
||||
}
|
||||
if d.Value != "foo" {
|
||||
t.Fatalf("TestDataUpdate: Value check failed")
|
||||
}
|
||||
|
||||
d = Data{Faker: "_", Value: "foo"}
|
||||
d.Update(row, manager)
|
||||
if d.IsUpdated {
|
||||
t.Fatalf("TestDataUpdate: IsUpdated check failed")
|
||||
}
|
||||
if d.Value != "foo" {
|
||||
t.Fatalf("TestDataUpdate: Value check failed")
|
||||
}
|
||||
|
||||
d = Data{Faker: "address", Value: "foo"}
|
||||
d.Update(row, manager)
|
||||
if !d.IsUpdated {
|
||||
t.Fatalf("TestDataUpdate: IsUpdated check failed")
|
||||
}
|
||||
if d.Value == "foo" && len(d.Value) > 0 {
|
||||
t.Fatalf("TestDataUpdate: Value check failed")
|
||||
}
|
||||
|
||||
d = Data{Faker: "Twig {{ bar }}", Value: "foo"}
|
||||
d.Update(row, manager)
|
||||
if !d.IsUpdated {
|
||||
t.Fatalf("TestDataUpdate: IsUpdated check failed")
|
||||
}
|
||||
if d.Value != "Twig bar_value" {
|
||||
t.Fatalf("TestDataUpdate: Value check failed")
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue