Files

83 lines
2.6 KiB
Go

package verdict
import "testing"
func TestCheckTool(t *testing.T) {
for _, c := range []struct {
tool, dialect string
ok bool
}{
{"liquibase", "postgres", true},
{"liquibase", "tsql", true},
{"liquibase", "oracle", true},
{"flyway", "mysql", true},
{"atlas", "postgres", true},
{"atlas", "mysql", true},
{"none", "tsql", true},
// A typo must fail, not fall through to some other tool.
{"liquibse", "postgres", false},
{"", "postgres", false},
{"sqitch", "postgres", false},
{"Liquibase", "postgres", false},
// Atlas Community has no SQL Server or Oracle driver.
{"atlas", "tsql", false},
{"atlas", "oracle", false},
} {
err := CheckTool(c.tool, c.dialect)
if (err == nil) != c.ok {
t.Errorf("CheckTool(%q, %q) = %v, want ok=%v", c.tool, c.dialect, err, c.ok)
}
}
}
// --engine names what the platform judges the SQL as; with it, --dialect keeps
// its default and is not sent (the endpoint refuses a request naming both).
func TestResolveTarget(t *testing.T) {
for _, tc := range []struct {
engine, dialect string
want Target
ok bool
}{
{"", "mysql", Target{Dialect: "mysql"}, true},
{"", "", Target{}, true}, // neither: nothing sent, the platform decides
{" SnowFlake ", "", Target{Engine: "snowflake"}, true},
{"postgres", "postgres", Target{}, false},
{"mongodb", "", Target{Engine: "mongodb"}, true},
{"oracle", "tsql", Target{}, false},
} {
got, err := ResolveTarget(tc.engine, tc.dialect)
if (err == nil) != tc.ok || got != tc.want {
t.Errorf("ResolveTarget(%q, %q) = %+v, %v", tc.engine, tc.dialect, got, err)
}
}
}
func TestAtlasRunsOnlyWhatItsCommunityEditionMigrates(t *testing.T) {
for engine, ok := range map[string]bool{
"postgres": true, "postgresql": true, "mysql": true, "mariadb": true,
"snowflake": false, "mongodb": false, "sqlserver": false, "oracle": false,
} {
target, err := ResolveTarget(engine, "")
if err != nil {
t.Fatal(err)
}
if err := CheckTool("atlas", target.ToolDialect()); (err == nil) != ok {
t.Errorf("atlas on %s: err = %v", engine, err)
}
// The other tools bring the driver the tenant gives them.
if err := CheckTool("liquibase", target.ToolDialect()); err != nil {
t.Errorf("liquibase on %s: %v", engine, err)
}
}
}
// Neither named: atlas's local dev database is PostgreSQL, as before.
func TestToolDialectDefaultsToPostgres(t *testing.T) {
if got := (Target{}).ToolDialect(); got != DefaultDialect {
t.Fatalf("ToolDialect() = %q", got)
}
if err := CheckTool("atlas", (Target{}).ToolDialect()); err != nil {
t.Fatal(err)
}
}