Added a test and fixed a typo

This commit is contained in:
Alex Gaynor 2014-08-11 11:47:56 -07:00
parent 9d6e0e4e83
commit e85b89d7fb
2 changed files with 18 additions and 1 deletions

View File

@ -123,7 +123,7 @@ func expandUserPath(path string) (string, error) {
}
userhome = u.HomeDir
}
userhome = strings.TrimSuffix(path, "/")
userhome = strings.TrimSuffix(userhome, "/")
return userhome + path[i:], nil
}

View File

@ -1,11 +1,28 @@
package ssh
import (
"os/user"
"strings"
"testing"
"github.com/hashicorp/terraform/terraform"
)
func Test_expandUserPath(t *testing.T) {
path, err := expandUserPath("~/path.pem")
if err != nil {
t.Fatalf("err: %v", err)
}
u, err := user.Current()
if err != nil {
t.Fatalf("err: %v", err)
}
expected := strings.TrimSuffix(u.HomeDir, "/") + "/path.pem"
if path != expected {
t.Fatalf("bad: %v", path)
}
}
func TestResourceProvider_verifySSH(t *testing.T) {
r := &terraform.ResourceState{
ConnInfo: map[string]string{