Skip to content

Commit

Permalink
refactor: move prompt to restore
Browse files Browse the repository at this point in the history
Signed-off-by: mlycore <[email protected]>
  • Loading branch information
mlycore committed Nov 16, 2023
1 parent e6ce1ce commit 8dcf177
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
16 changes: 10 additions & 6 deletions pitr/cli/internal/cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ func restore() error {
return xerr.NewCliErr(fmt.Sprintf("check database exist failed. err: %s", err))
}

prompt := fmt.Sprintf(
"Detected That The Database [%s] Already Exists In ShardingSphere-Proxy Metadata.\n"+
"The Logic Database Will Be DROPPED And Then Insert Backup's Metadata Into ShardingSphere-Proxy After Restoring The Backup Data.\n"+
"Are you sure to continue? (Y/N)", strings.Join(databaseNamesExist, ","))
err = getUserApproveInTerminal(prompt)
if err != nil {
return xerr.NewCliErr(fmt.Sprintf("%s", err))
}

// check agent server status
logging.Info("Checking agent server status...")
if available := checkAgentServerStatus(bak); !available {
Expand Down Expand Up @@ -150,12 +159,7 @@ func checkDatabaseExist(proxy pkg.IShardingSphereProxy, bak *model.LsBackup) err
return nil
}

// get user input to confirm
prompt := fmt.Sprintf(
"Detected That The Database [%s] Already Exists In ShardingSphere-Proxy Metadata.\n"+
"The Logic Database Will Be DROPPED And Then Insert Backup's Metadata Into ShardingSphere-Proxy After Restoring The Backup Data.\n"+
"Are you sure to continue? (Y/N)", strings.Join(databaseNamesExist, ","))
return getUserApproveInTerminal(prompt)
return nil
}

func restoreDataToSSProxy(proxy pkg.IShardingSphereProxy, lsBackup *model.LsBackup) error {
Expand Down
12 changes: 3 additions & 9 deletions pitr/cli/internal/cmd/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ var _ = Describe("test restore", func() {
monkey.Patch(pkg.NewLocalStorage, func(rootDir string) (pkg.ILocalStorage, error) {
return ls, nil
})
monkey.Patch(getUserApproveInTerminal, func(_ string) error {
return nil
})
})

AfterEach(func() {
Expand Down Expand Up @@ -131,15 +134,6 @@ var _ = Describe("test restore", func() {
Expect(restore()).To(BeNil())
})

// test getUserApproveInTerminal
Context("test userApproveInTerminal", func() {
// test user abort
It("user abort", func() {
// exec getUserApproveInTerminal
Expect(getUserApproveInTerminal("")).To(Equal(xerr.NewCliErr("User abort")))
})
})

Context("restore data to ss proxy", func() {

It("no need to drop database", func() {
Expand Down

0 comments on commit 8dcf177

Please sign in to comment.