From f4946b3c08c0bf310e0348d8ab97213538d4f537 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Wed, 20 Mar 2024 11:42:28 +0100 Subject: [PATCH] add tests --- config/config_test.go | 49 +++++++++++++++++++++++++++++++++++++++ database/database_test.go | 15 ++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 config/config_test.go create mode 100644 database/database_test.go diff --git a/config/config_test.go b/config/config_test.go new file mode 100644 index 0000000..098fd2a --- /dev/null +++ b/config/config_test.go @@ -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") + } +} diff --git a/database/database_test.go b/database/database_test.go new file mode 100644 index 0000000..c5666b8 --- /dev/null +++ b/database/database_test.go @@ -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") + } +}