提交 37673c85 作者: Jeromy

add a test for auto migrations cli interface

License: MIT
Signed-off-by: 's avatarJeromy <why@ipfs.io>
上级 cc73137f
......@@ -225,6 +225,7 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
return
case fsrepo.ErrNeedMigration:
domigrate, found, _ := req.Option(migrateKwd).Bool()
fmt.Println("Found old repo version, migrations need to be run.")
if !found {
err = migrate.TryMigrating(fsrepo.RepoVersion)
......
......@@ -61,7 +61,7 @@ func (v VersionFileNotFound) Error() string {
}
func TryMigrating(tovers int) error {
if !YesNoPrompt("run migrations automatically? [y/n]") {
if !YesNoPrompt("Run migrations automatically? [y/N]") {
return fmt.Errorf("please run the migrations manually")
}
......@@ -70,7 +70,7 @@ func TryMigrating(tovers int) error {
func YesNoPrompt(prompt string) bool {
var s string
for {
for i := 0; i < 3; i++ {
fmt.Printf("%s ", prompt)
fmt.Scanf("%s", &s)
switch s {
......@@ -78,7 +78,11 @@ func YesNoPrompt(prompt string) bool {
return true
case "n", "N":
return false
case "":
return false
}
fmt.Println("Please press either 'y' or 'n'")
}
return false
}
......@@ -27,7 +27,9 @@ const migrations = "fs-repo-migrations"
func RunMigration(newv int) error {
migrateBin := "fs-repo-migrations"
fmt.Println(" => checking for migrations binary...")
_, err := exec.LookPath(migrateBin)
var err error
migrateBin, err = exec.LookPath(migrateBin)
if err == nil {
// check to make sure migrations binary supports our target version
err = verifyMigrationSupportsVersion(migrateBin, newv)
......
#!/bin/sh
#
# Copyright (c) 2016 Jeromy Johnson
# MIT Licensed; see the LICENSE file in this repository.
#
test_description="Test migrations auto update prompt"
. lib/test-lib.sh
test_init_ipfs
test_expect_success "setup mock migrations" '
mkdir bin &&
echo "#!/bin/bash" > bin/fs-repo-migrations &&
echo "echo 4" >> bin/fs-repo-migrations &&
chmod +x bin/fs-repo-migrations &&
export PATH="$(pwd)/bin":$PATH
'
test_expect_success "manually reset repo version to 3" '
echo "3" > "$IPFS_PATH"/version
'
test_expect_success "ipfs daemon --migrate=false fails" '
test_expect_code 1 ipfs daemon --migrate=false 2> false_out
'
test_expect_success "output looks good" '
grep "ipfs repo needs migration" false_out
'
test_expect_success "ipfs daemon --migrate=true runs migration" '
test_expect_code 1 ipfs daemon --migrate=true > true_out
'
test_expect_success "output looks good" '
grep "running migration" true_out > /dev/null &&
grep "binary completed successfully" true_out > /dev/null
'
test_expect_success "'ipfs daemon' prompts to auto migrate" '
test_expect_code 1 ipfs daemon > daemon_out 2> daemon_err
'
test_expect_success "output looks good" '
grep "Found old repo version" daemon_out > /dev/null &&
grep "Run migrations automatically?" daemon_out > /dev/null &&
grep "please run the migrations manually" daemon_err > /dev/null
'
test_done
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论