Skip to content

Commit

Permalink
✅ Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Jun 29, 2022
1 parent 81973fe commit 4d4b3d8
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 30 deletions.
8 changes: 4 additions & 4 deletions cmd/dump/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ func Test_buildCommand(t *testing.T) {
{
"postgres-gzip",
args{dialect.Postgres{}, config.Dump{Global: config.Global{Database: "d", Username: "u"}}},
command.NewBuilder(pgpassword, "pg_dump", "--host=127.0.0.1", "--username=u", "--dbname=d", command.Pipe, "gzip", "--force"),
command.NewBuilder(pgpassword, "pg_dump", "--host=127.0.0.1", "--username=u", "--dbname=d", "--verbose", command.Pipe, "gzip", "--force"),
},
{
"postgres-plain",
args{dialect.Postgres{}, config.Dump{Files: config.Files{Format: sqlformat.Plain}, Global: config.Global{Database: "d", Username: "u"}}},
command.NewBuilder(pgpassword, "pg_dump", "--host=127.0.0.1", "--username=u", "--dbname=d", command.Pipe, "gzip", "--force"),
command.NewBuilder(pgpassword, "pg_dump", "--host=127.0.0.1", "--username=u", "--dbname=d", "--verbose", command.Pipe, "gzip", "--force"),
},
{
"postgres-custom",
args{dialect.Postgres{}, config.Dump{Files: config.Files{Format: sqlformat.Custom}, Global: config.Global{Database: "d", Username: "u"}}},
command.NewBuilder(pgpassword, "pg_dump", "--host=127.0.0.1", "--username=u", "--dbname=d", "--format=c"),
command.NewBuilder(pgpassword, "pg_dump", "--host=127.0.0.1", "--username=u", "--dbname=d", "--format=c", "--verbose"),
},
{
"mariadb-gzip",
args{dialect.MariaDB{}, config.Dump{Files: config.Files{Format: sqlformat.Gzip}, Global: config.Global{Database: "d", Username: "u"}}},
command.NewBuilder(mysql_pwd, "mysqldump", "--host=127.0.0.1", "--user=u", "d", command.Pipe, "gzip", "--force"),
command.NewBuilder(mysql_pwd, "mysqldump", "--host=127.0.0.1", "--user=u", "d", "--verbose", command.Pipe, "gzip", "--force"),
},
}
for _, tt := range tests {
Expand Down
7 changes: 3 additions & 4 deletions cmd/restore/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

func Test_buildCommand(t *testing.T) {
pgpassword := command.NewEnv("PGPASSWORD", "")
pgoptions := command.NewEnv("PGOPTIONS", "-c client_min_messages=WARNING")

type args struct {
conf config.Restore
Expand All @@ -32,23 +31,23 @@ func Test_buildCommand(t *testing.T) {
config.Restore{Global: config.Global{Dialect: dialect.Postgres{}, Database: "d", Username: "u"}},
sqlformat.Gzip,
},
command.NewBuilder("gunzip", "--force", command.Pipe, pgpassword, pgoptions, "psql", "--quiet", "--output=/dev/null", "--host=127.0.0.1", "--username=u", "--dbname=d"),
command.NewBuilder("gunzip", "--force", command.Pipe, pgpassword, "psql", "--host=127.0.0.1", "--username=u", "--dbname=d"),
},
{
"postgres-plain",
args{
config.Restore{Global: config.Global{Dialect: dialect.Postgres{}, Database: "d", Username: "u"}},
sqlformat.Gzip,
},
command.NewBuilder("gunzip", "--force", command.Pipe, pgpassword, pgoptions, "psql", "--quiet", "--output=/dev/null", "--host=127.0.0.1", "--username=u", "--dbname=d"),
command.NewBuilder("gunzip", "--force", command.Pipe, pgpassword, "psql", "--host=127.0.0.1", "--username=u", "--dbname=d"),
},
{
"postgres-custom",
args{
config.Restore{Global: config.Global{Dialect: dialect.Postgres{}, Database: "d", Username: "u"}},
sqlformat.Gzip,
},
command.NewBuilder("gunzip", "--force", command.Pipe, pgpassword, pgoptions, "psql", "--quiet", "--output=/dev/null", "--host=127.0.0.1", "--username=u", "--dbname=d"),
command.NewBuilder("gunzip", "--force", command.Pipe, pgpassword, "psql", "--host=127.0.0.1", "--username=u", "--dbname=d"),
},
}
for _, tt := range tests {
Expand Down
16 changes: 8 additions & 8 deletions internal/database/dialect/mariadb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestMariaDB_DropDatabaseQuery(t *testing.T) {
args args
want string
}{
{"database", args{"database"}, "set FOREIGN_KEY_CHECKS=0; create or replace database database; set FOREIGN_KEY_CHECKS=1;"},
{"database", args{"database"}, "set FOREIGN_KEY_CHECKS=0; create or replace database database; set FOREIGN_KEY_CHECKS=1; use database;"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -111,22 +111,22 @@ func TestMariaDB_DumpCommand(t *testing.T) {
{
"default",
args{config.Dump{Global: config.Global{Database: "d", Username: "u"}}},
command.NewBuilder(command.NewEnv("MYSQL_PWD", ""), "mysqldump", "--host=127.0.0.1", "--user=u", "d"),
command.NewBuilder(command.NewEnv("MYSQL_PWD", ""), "mysqldump", "--host=127.0.0.1", "--user=u", "d", "--verbose"),
},
{
"clean",
args{config.Dump{Clean: true, Global: config.Global{Database: "d", Username: "u"}}},
command.NewBuilder(command.NewEnv("MYSQL_PWD", ""), "mysqldump", "--host=127.0.0.1", "--user=u", "d", "--add-drop-table"),
command.NewBuilder(command.NewEnv("MYSQL_PWD", ""), "mysqldump", "--host=127.0.0.1", "--user=u", "d", "--add-drop-table", "--verbose"),
},
{
"tables",
args{config.Dump{Tables: []string{"table1", "table2"}, Global: config.Global{Database: "d", Username: "u"}}},
command.NewBuilder(command.NewEnv("MYSQL_PWD", ""), "mysqldump", "--host=127.0.0.1", "--user=u", "d", "table1", "table2"),
command.NewBuilder(command.NewEnv("MYSQL_PWD", ""), "mysqldump", "--host=127.0.0.1", "--user=u", "d", "table1", "table2", "--verbose"),
},
{
"exclude-table",
args{config.Dump{ExcludeTable: []string{"table1", "table2"}, Global: config.Global{Database: "d", Username: "u"}}},
command.NewBuilder(command.NewEnv("MYSQL_PWD", ""), "mysqldump", "--host=127.0.0.1", "--user=u", "d", "--ignore-table=table1", "--ignore-table=table2"),
command.NewBuilder(command.NewEnv("MYSQL_PWD", ""), "mysqldump", "--host=127.0.0.1", "--user=u", "d", "--ignore-table=table1", "--ignore-table=table2", "--verbose"),
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -306,17 +306,17 @@ func TestMariaDB_RestoreCommand(t *testing.T) {
{
"gzip",
args{config.Restore{Global: config.Global{Database: "d", Username: "u"}}, sqlformat.Gzip},
command.NewBuilder(command.Env{Key: "MYSQL_PWD"}, "mysql", "--host=127.0.0.1", "--user=u", "d"),
command.NewBuilder(command.Env{Key: "MYSQL_PWD"}, "mysql", "--host=127.0.0.1", "--user=u", "--database=d"),
},
{
"plain",
args{config.Restore{Global: config.Global{Database: "d", Username: "u"}}, sqlformat.Plain},
command.NewBuilder(command.Env{Key: "MYSQL_PWD"}, "mysql", "--host=127.0.0.1", "--user=u", "d"),
command.NewBuilder(command.Env{Key: "MYSQL_PWD"}, "mysql", "--host=127.0.0.1", "--user=u", "--database=d"),
},
{
"custom",
args{config.Restore{Global: config.Global{Database: "d", Username: "u"}}, sqlformat.Custom},
command.NewBuilder(command.Env{Key: "MYSQL_PWD"}, "mysql", "--host=127.0.0.1", "--user=u", "d"),
command.NewBuilder(command.Env{Key: "MYSQL_PWD"}, "mysql", "--host=127.0.0.1", "--user=u", "--database=d"),
},
}
for _, tt := range tests {
Expand Down
10 changes: 10 additions & 0 deletions internal/database/dialect/mongodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ func TestMongoDB_DumpCommand(t *testing.T) {
args{config.Dump{ExcludeTable: []string{"table1", "table2"}, Global: config.Global{Database: "d", Username: "u", Password: "p"}}},
command.NewBuilder("mongodump", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--db=d", "--excludeCollection=table1", "--excludeCollection=table2"),
},
{
"quiet",
args{config.Dump{Global: config.Global{Database: "d", Username: "u", Password: "p", Quiet: true}}},
command.NewBuilder("mongodump", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--db=d", "--quiet"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -323,6 +328,11 @@ func TestMongoDB_RestoreCommand(t *testing.T) {
args{config.Restore{Clean: true, Global: config.Global{Database: "d", Username: "u", Password: "p"}}, sqlformat.Gzip},
command.NewBuilder("mongorestore", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--drop", "--db=d"),
},
{
"quiet",
args{config.Restore{Global: config.Global{Database: "d", Username: "u", Password: "p", Quiet: true}}, sqlformat.Gzip},
command.NewBuilder("mongorestore", "--archive", "--host=127.0.0.1", "--username=u", "--password=p", "--db=d", "--quiet"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
32 changes: 18 additions & 14 deletions internal/database/dialect/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,42 +112,42 @@ func TestPostgres_DumpCommand(t *testing.T) {
{
"default",
args{config.Dump{Global: config.Global{Database: "d", Username: "u"}}},
command.NewBuilder(command.NewEnv("PGPASSWORD", ""), "pg_dump", "--host=127.0.0.1", "--username=u", "--dbname=d"),
command.NewBuilder(command.NewEnv("PGPASSWORD", ""), "pg_dump", "--host=127.0.0.1", "--username=u", "--dbname=d", "--verbose"),
},
{
"clean",
args{config.Dump{Clean: true, Global: config.Global{Database: "d", Username: "u"}}},
command.NewBuilder(command.NewEnv("PGPASSWORD", ""), "pg_dump", "--host=127.0.0.1", "--username=u", "--dbname=d", "--clean"),
command.NewBuilder(command.NewEnv("PGPASSWORD", ""), "pg_dump", "--host=127.0.0.1", "--username=u", "--dbname=d", "--clean", "--verbose"),
},
{
"no-owner",
args{config.Dump{NoOwner: true, Global: config.Global{Database: "d", Username: "u"}}},
command.NewBuilder(command.NewEnv("PGPASSWORD", ""), "pg_dump", "--host=127.0.0.1", "--username=u", "--dbname=d", "--no-owner"),
command.NewBuilder(command.NewEnv("PGPASSWORD", ""), "pg_dump", "--host=127.0.0.1", "--username=u", "--dbname=d", "--no-owner", "--verbose"),
},
{
"if-exists",
args{config.Dump{IfExists: true, Global: config.Global{Database: "d", Username: "u"}}},
command.NewBuilder(command.NewEnv("PGPASSWORD", ""), "pg_dump", "--host=127.0.0.1", "--username=u", "--dbname=d", "--if-exists"),
command.NewBuilder(command.NewEnv("PGPASSWORD", ""), "pg_dump", "--host=127.0.0.1", "--username=u", "--dbname=d", "--if-exists", "--verbose"),
},
{
"tables",
args{config.Dump{Tables: []string{"table1", "table2"}, Global: config.Global{Database: "d", Username: "u"}}},
command.NewBuilder(command.NewEnv("PGPASSWORD", ""), "pg_dump", "--host=127.0.0.1", "--username=u", "--dbname=d", `--table="table1"`, `--table="table2"`),
command.NewBuilder(command.NewEnv("PGPASSWORD", ""), "pg_dump", "--host=127.0.0.1", "--username=u", "--dbname=d", `--table="table1"`, `--table="table2"`, "--verbose"),
},
{
"exclude-table",
args{config.Dump{ExcludeTable: []string{"table1", "table2"}, Global: config.Global{Database: "d", Username: "u"}}},
command.NewBuilder(command.NewEnv("PGPASSWORD", ""), "pg_dump", "--host=127.0.0.1", "--username=u", "--dbname=d", `--exclude-table="table1"`, `--exclude-table="table2"`),
command.NewBuilder(command.NewEnv("PGPASSWORD", ""), "pg_dump", "--host=127.0.0.1", "--username=u", "--dbname=d", `--exclude-table="table1"`, `--exclude-table="table2"`, "--verbose"),
},
{
"exclude-table-data",
args{config.Dump{ExcludeTableData: []string{"table1", "table2"}, Global: config.Global{Database: "d", Username: "u"}}},
command.NewBuilder(command.NewEnv("PGPASSWORD", ""), "pg_dump", "--host=127.0.0.1", "--username=u", "--dbname=d", `--exclude-table-data="table1"`, `--exclude-table-data="table2"`),
command.NewBuilder(command.NewEnv("PGPASSWORD", ""), "pg_dump", "--host=127.0.0.1", "--username=u", "--dbname=d", `--exclude-table-data="table1"`, `--exclude-table-data="table2"`, "--verbose"),
},
{
"custom",
args{config.Dump{Files: config.Files{Format: sqlformat.Custom}, Global: config.Global{Database: "d", Username: "u"}}},
command.NewBuilder(command.NewEnv("PGPASSWORD", ""), "pg_dump", "--host=127.0.0.1", "--username=u", "--dbname=d", "--format=c"),
command.NewBuilder(command.NewEnv("PGPASSWORD", ""), "pg_dump", "--host=127.0.0.1", "--username=u", "--dbname=d", "--format=c", "--verbose"),
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -353,7 +353,6 @@ func TestPostgres_PodLabels(t *testing.T) {

func TestPostgres_RestoreCommand(t *testing.T) {
pgpassword := command.NewEnv("PGPASSWORD", "")
pgoptions := command.NewEnv("PGOPTIONS", "-c client_min_messages=WARNING")

type args struct {
conf config.Restore
Expand All @@ -367,27 +366,32 @@ func TestPostgres_RestoreCommand(t *testing.T) {
{
"gzip",
args{config.Restore{Global: config.Global{Database: "d", Username: "u"}}, sqlformat.Gzip},
command.NewBuilder(pgpassword, pgoptions, "psql", "--quiet", "--output=/dev/null", "--host=127.0.0.1", "--username=u", "--dbname=d"),
command.NewBuilder(pgpassword, "psql", "--host=127.0.0.1", "--username=u", "--dbname=d"),
},
{
"plain",
args{config.Restore{Global: config.Global{Database: "d", Username: "u"}}, sqlformat.Plain},
command.NewBuilder(pgpassword, pgoptions, "psql", "--quiet", "--output=/dev/null", "--host=127.0.0.1", "--username=u", "--dbname=d"),
command.NewBuilder(pgpassword, "psql", "--host=127.0.0.1", "--username=u", "--dbname=d"),
},
{
"custom",
args{config.Restore{Global: config.Global{Database: "d", Username: "u"}}, sqlformat.Custom},
command.NewBuilder(pgpassword, pgoptions, "pg_restore", "--format=custom", "--verbose", "--clean", "--exit-on-error", "--host=127.0.0.1", "--username=u", "--dbname=d"),
command.NewBuilder(pgpassword, "pg_restore", "--format=custom", "--clean", "--exit-on-error", "--verbose", "--host=127.0.0.1", "--username=u", "--dbname=d"),
},
{
"custom-no-owner",
args{config.Restore{NoOwner: true, Global: config.Global{Database: "d", Username: "u"}}, sqlformat.Custom},
command.NewBuilder(pgpassword, pgoptions, "pg_restore", "--format=custom", "--verbose", "--clean", "--exit-on-error", "--no-owner", "--host=127.0.0.1", "--username=u", "--dbname=d"),
command.NewBuilder(pgpassword, "pg_restore", "--format=custom", "--clean", "--exit-on-error", "--no-owner", "--verbose", "--host=127.0.0.1", "--username=u", "--dbname=d"),
},
{
"single-transaction",
args{config.Restore{SingleTransaction: true, Global: config.Global{Database: "d", Username: "u"}}, sqlformat.Custom},
command.NewBuilder(pgpassword, pgoptions, "pg_restore", "--format=custom", "--verbose", "--clean", "--exit-on-error", "--host=127.0.0.1", "--username=u", "--dbname=d", "--single-transaction"),
command.NewBuilder(pgpassword, "pg_restore", "--format=custom", "--clean", "--exit-on-error", "--verbose", "--host=127.0.0.1", "--username=u", "--dbname=d", "--single-transaction"),
},
{
"sql-quiet",
args{config.Restore{Global: config.Global{Database: "d", Username: "u", Quiet: true}}, sqlformat.Gzip},
command.NewBuilder(pgpassword, command.NewEnv("PGOPTIONS", "-c client_min_messages=WARNING"), "psql", "--quiet", "--output=/dev/null", "--host=127.0.0.1", "--username=u", "--dbname=d"),
},
}
for _, tt := range tests {
Expand Down

0 comments on commit 4d4b3d8

Please sign in to comment.