TestEditorEnvFallback asserts that env vars are used as fallback when no editor is specified in the config file
(t *testing.T)
| 390 | // TestEditorEnvFallback asserts that env vars are used as fallback when |
| 391 | // no editor is specified in the config file |
| 392 | func TestEditorEnvFallback(t *testing.T) { |
| 393 | // save and clear the environment variables |
| 394 | oldVisual := os.Getenv("VISUAL") |
| 395 | oldEditor := os.Getenv("EDITOR") |
| 396 | defer func() { |
| 397 | os.Setenv("VISUAL", oldVisual) |
| 398 | os.Setenv("EDITOR", oldEditor) |
| 399 | }() |
| 400 | |
| 401 | // set $EDITOR and assert it's used when config has no editor |
| 402 | os.Unsetenv("VISUAL") |
| 403 | os.Setenv("EDITOR", "foo") |
| 404 | conf, err := New(mocks.Path("conf/empty.yml"), false) |
| 405 | if err != nil { |
| 406 | t.Fatalf("failed to init configs: %v", err) |
| 407 | } |
| 408 | if conf.Editor != "foo" { |
| 409 | t.Errorf("failed to respect $EDITOR: want: foo, got: %s", conf.Editor) |
| 410 | } |
| 411 | |
| 412 | // set $VISUAL and assert it takes precedence over $EDITOR |
| 413 | os.Setenv("VISUAL", "bar") |
| 414 | conf, err = New(mocks.Path("conf/empty.yml"), false) |
| 415 | if err != nil { |
| 416 | t.Fatalf("failed to init configs: %v", err) |
| 417 | } |
| 418 | if conf.Editor != "bar" { |
| 419 | t.Errorf("failed to respect $VISUAL: want: bar, got: %s", conf.Editor) |
| 420 | } |
| 421 | } |