TestConfig asserts that the configs are loaded correctly
(t *testing.T)
| 262 | |
| 263 | // TestConfig asserts that the configs are loaded correctly |
| 264 | func TestConfigSuccessful(t *testing.T) { |
| 265 | |
| 266 | // Chdir into a temp directory so no ancestor .cheat directory can |
| 267 | // leak into the cheatpaths (findLocalCheatpath walks the full |
| 268 | // ancestor chain). |
| 269 | oldCwd, err := os.Getwd() |
| 270 | if err != nil { |
| 271 | t.Fatalf("failed to get cwd: %v", err) |
| 272 | } |
| 273 | defer os.Chdir(oldCwd) |
| 274 | if err := os.Chdir(t.TempDir()); err != nil { |
| 275 | t.Fatalf("failed to chdir: %v", err) |
| 276 | } |
| 277 | |
| 278 | // clear env vars so they don't override the config file value |
| 279 | oldVisual := os.Getenv("VISUAL") |
| 280 | oldEditor := os.Getenv("EDITOR") |
| 281 | os.Unsetenv("VISUAL") |
| 282 | os.Unsetenv("EDITOR") |
| 283 | defer func() { |
| 284 | os.Setenv("VISUAL", oldVisual) |
| 285 | os.Setenv("EDITOR", oldEditor) |
| 286 | }() |
| 287 | |
| 288 | // initialize a config |
| 289 | conf, err := New(mocks.Path("conf/conf.yml"), false) |
| 290 | if err != nil { |
| 291 | t.Errorf("failed to parse config file: %v", err) |
| 292 | } |
| 293 | |
| 294 | // assert that the expected values were returned |
| 295 | if conf.Editor != "vim" { |
| 296 | t.Errorf("failed to set editor: want: vim, got: %s", conf.Editor) |
| 297 | } |
| 298 | if !conf.Colorize { |
| 299 | t.Errorf("failed to set colorize: want: true, got: %t", conf.Colorize) |
| 300 | } |
| 301 | |
| 302 | // get the user's home directory (with ~ expanded) |
| 303 | home, err := homedir.Dir() |
| 304 | if err != nil { |
| 305 | t.Errorf("failed to get homedir: %v", err) |
| 306 | } |
| 307 | |
| 308 | // assert that the cheatpaths are correct |
| 309 | want := []cheatpath.Path{ |
| 310 | cheatpath.Path{ |
| 311 | Path: filepath.Join(home, ".dotfiles", "cheat", "community"), |
| 312 | ReadOnly: true, |
| 313 | Tags: []string{"community"}, |
| 314 | }, |
| 315 | cheatpath.Path{ |
| 316 | Path: filepath.Join(home, ".dotfiles", "cheat", "work"), |
| 317 | ReadOnly: false, |
| 318 | Tags: []string{"work"}, |
| 319 | }, |
| 320 | cheatpath.Path{ |
| 321 | Path: filepath.Join(home, ".dotfiles", "cheat", "personal"), |