Better approach plus tests

This commit is contained in:
Zach Musgrave
2023-07-21 16:54:19 -07:00
parent 1bf52a93f4
commit 951c55140a
2 changed files with 34 additions and 2 deletions

View File

@@ -87,7 +87,7 @@ func (cmd BackupCmd) Description() string {
}
func (cmd BackupCmd) RequiresRepo() bool {
return true
return false
}
func (cmd BackupCmd) Docs() *cli.CommandDocumentation {
@@ -112,6 +112,13 @@ func (cmd BackupCmd) Exec(ctx context.Context, commandStr string, args []string,
var verr errhand.VerboseError
// All the sub commands except `restore` require a valid environment
if apr.NArg() == 0 || apr.Arg(0) != cli.RestoreBackupId {
if !cli.CheckEnvIsValid(dEnv) {
return 2
}
}
switch {
case apr.NArg() == 0:
verr = printBackups(dEnv, apr)

View File

@@ -32,6 +32,10 @@ teardown() {
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 1 ]
[[ "$output" =~ "bac1" ]] || false
mkdir newdir && cd newdir
run dolt backup add bac1 file://../bac1
[ "$status" -ne 0 ]
}
@test "backup: remove named backup" {
@@ -48,6 +52,10 @@ teardown() {
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 0 ]
[[ ! "$output" =~ "bac1" ]] || false
mkdir newdir && cd newdir
run dolt backup remove bac1
[ "$status" -ne 0 ]
}
@test "backup: rm named backup" {
@@ -64,6 +72,10 @@ teardown() {
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 0 ]
[[ ! "$output" =~ "bac1" ]] || false
mkdir newdir && cd newdir
run dolt backup rm bac1
[ "$status" -ne 0 ]
}
@test "backup: removing a backup with the same name as a remote does not impact remote tracking refs" {
@@ -84,7 +96,7 @@ teardown() {
dolt backup sync bac1
cd ..
run dolt backup restore file://./bac1 repo2
dolt backup restore file://./bac1 repo2
cd repo2
run dolt ls
[ "$status" -eq 0 ]
@@ -92,6 +104,12 @@ teardown() {
[[ "$output" =~ "t1" ]] || false
}
@test "backup: sync in a non-dolt directory" {
mkdir newdir && cd newdir
run dolt backup sync bac1
[ "$status" -ne 0 ]
}
@test "backup: sync feature to backup" {
cd repo1
dolt backup add bac1 file://../bac1
@@ -251,3 +269,10 @@ teardown() {
[ "${#lines[@]}" -eq 2 ]
[[ "$output" =~ "t1" ]] || false
}
@test "backup: sync-url in a non-dolt directory" {
mkdir newdir && cd newdir
run dolt backup sync-url file://../bac1
[ "$status" -ne 0 ]
}