Skip to content

Commit

Permalink
Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeemster committed Sep 2, 2020
1 parent 927642f commit 2aba0ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion sql_runner/main.go
Expand Up @@ -237,7 +237,7 @@ func resolveSqlRoot(sqlroot string, playbookPath string, consulAddress string, c
if err != nil {
return "", nil
}
return strings.Replace(sqlroot, SQLROOT_PLAYBOOK, absPlaybookPath, 1), nil
return strings.ReplaceAll(sqlroot, "PLAYBOOK", absPlaybookPath), nil
}

return sqlroot, nil
Expand All @@ -261,6 +261,15 @@ func resolveSqlRoot(sqlroot string, playbookPath string, consulAddress string, c
}
return "", consulErr2
default:
// For allowing relative paths from the playbook
if strings.HasPrefix(sqlroot, SQLROOT_PLAYBOOK) {
absPlaybookPath, err := filepath.Abs(filepath.Dir(playbookPath))
if err != nil {
return "", nil
}
return strings.ReplaceAll(sqlroot, "PLAYBOOK", absPlaybookPath), nil
}

return sqlroot, nil
}
}
Expand Down
5 changes: 5 additions & 0 deletions sql_runner/main_test.go
Expand Up @@ -107,4 +107,9 @@ func TestResolveSqlRoot(t *testing.T) {
assert.NotNil(str)
assert.Nil(err)
assert.Equal("random", str)

str, err = resolveSqlRoot(SQLROOT_PLAYBOOK+"/../sql/", "../integration/resources/good-postgres.yml", "", true)
assert.NotNil(str)
assert.Nil(err)
assert.True(strings.HasSuffix(str, "/integration/resources/../sql/"))
}

0 comments on commit 2aba0ca

Please sign in to comment.