MCPcopy
hub / github.com/cheat/cheat / TestEditorEnvFallback

Function TestEditorEnvFallback

internal/config/config_test.go:392–421  ·  view source on GitHub ↗

TestEditorEnvFallback asserts that env vars are used as fallback when no editor is specified in the config file

(t *testing.T)

Source from the content-addressed store, hash-verified

390// TestEditorEnvFallback asserts that env vars are used as fallback when
391// no editor is specified in the config file
392func 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}

Callers

nothing calls this directly

Calls 2

PathFunction · 0.92
NewFunction · 0.70

Tested by

no test coverage detected