| 54 | } |
| 55 | |
| 56 | func TestExpandPath(t *testing.T) { |
| 57 | for desc, c := range map[string]*ExpandPathTestCase{ |
| 58 | "no expand": { |
| 59 | Path: "/path/to/hooks", |
| 60 | Want: "/path/to/hooks", |
| 61 | }, |
| 62 | "current": { |
| 63 | Path: "~/path/to/hooks", |
| 64 | Want: "/home/jane/path/to/hooks", |
| 65 | currentUser: func() (*user.User, error) { |
| 66 | return &user.User{ |
| 67 | HomeDir: "/home/jane", |
| 68 | }, nil |
| 69 | }, |
| 70 | }, |
| 71 | "current, slash": { |
| 72 | Path: "~/", |
| 73 | Want: "/home/jane", |
| 74 | currentUser: func() (*user.User, error) { |
| 75 | return &user.User{ |
| 76 | HomeDir: "/home/jane", |
| 77 | }, nil |
| 78 | }, |
| 79 | }, |
| 80 | "current, no slash": { |
| 81 | Path: "~", |
| 82 | Want: "/home/jane", |
| 83 | currentUser: func() (*user.User, error) { |
| 84 | return &user.User{ |
| 85 | HomeDir: "/home/jane", |
| 86 | }, nil |
| 87 | }, |
| 88 | }, |
| 89 | "non-current": { |
| 90 | Path: "~other/path/to/hooks", |
| 91 | Want: "/home/special/path/to/hooks", |
| 92 | lookupUser: func(who string) (*user.User, error) { |
| 93 | assert.Equal(t, "other", who) |
| 94 | return &user.User{ |
| 95 | HomeDir: "/home/special", |
| 96 | }, nil |
| 97 | }, |
| 98 | }, |
| 99 | "non-current, no slash": { |
| 100 | Path: "~other", |
| 101 | Want: "/home/special", |
| 102 | lookupUser: func(who string) (*user.User, error) { |
| 103 | assert.Equal(t, "other", who) |
| 104 | return &user.User{ |
| 105 | HomeDir: "/home/special", |
| 106 | }, nil |
| 107 | }, |
| 108 | }, |
| 109 | "non-current (missing)": { |
| 110 | Path: "~other/path/to/hooks", |
| 111 | WantErr: "could not find user other: missing", |
| 112 | lookupUser: func(who string) (*user.User, error) { |
| 113 | assert.Equal(t, "other", who) |