forked from deblan/database-anonymizer
add tests
This commit is contained in:
parent
b547166c83
commit
f4946b3c08
2 changed files with 64 additions and 0 deletions
49
config/config_test.go
Normal file
49
config/config_test.go
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLoadDatabaseConfig(t *testing.T) {
|
||||
c, err := LoadDatabaseConfig("mysql://")
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("LoadDatabaseConfig: mysql dsn check failed")
|
||||
}
|
||||
|
||||
if c.Type != "mysql" {
|
||||
t.Fatalf("LoadDatabaseConfig: mysql type check failed")
|
||||
}
|
||||
|
||||
c, err = LoadDatabaseConfig("postgres://")
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("LoadDatabaseConfig: postgres dsn check failed")
|
||||
}
|
||||
|
||||
if c.Type != "postgres" {
|
||||
t.Fatalf("LoadDatabaseConfig: postgres type check failed")
|
||||
}
|
||||
|
||||
_, err = LoadDatabaseConfig("foo://")
|
||||
|
||||
if err == nil {
|
||||
t.Fatalf("LoadDatabaseConfig: lambda dsn check failed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSchemaConfigActionInitPrimaryKey(t *testing.T) {
|
||||
c := SchemaConfigAction{}
|
||||
c.InitPrimaryKey()
|
||||
|
||||
if len(c.PrimaryKey) != 1 || c.PrimaryKey[0] != "id" {
|
||||
t.Fatalf("TestSchemaConfigActionInitPrimaryKey: primary key check failed")
|
||||
}
|
||||
|
||||
c = SchemaConfigAction{PrimaryKey: []string{"foo", "bar"}}
|
||||
c.InitPrimaryKey()
|
||||
|
||||
if len(c.PrimaryKey) != 2 || c.PrimaryKey[0] != "foo" || c.PrimaryKey[1] != "bar" {
|
||||
t.Fatalf("TestSchemaConfigActionInitPrimaryKey: primary key check failed")
|
||||
}
|
||||
}
|
||||
15
database/database_test.go
Normal file
15
database/database_test.go
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEscapeTable(t *testing.T) {
|
||||
if EscapeTable("mysql", "foo") != "`foo`" {
|
||||
t.Fatalf("TestEscapeTable: mysql check failed")
|
||||
}
|
||||
|
||||
if EscapeTable("postgres", "foo") != "\"foo\"" {
|
||||
t.Fatalf("TestEscapeTable: postgres check failed")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue