MCPcopy Index your code
hub / github.com/cheat/cheat / TestEditorEnvOverride

Function TestEditorEnvOverride

internal/config/config_test.go:349–388  ·  view source on GitHub ↗

TestEditorEnvOverride asserts that $VISUAL and $EDITOR override the config file value at runtime (regression test for #589)

(t *testing.T)

Source from the content-addressed store, hash-verified

347// TestEditorEnvOverride asserts that $VISUAL and $EDITOR override the
348// config file value at runtime (regression test for #589)
349func TestEditorEnvOverride(t *testing.T) {
350 // save and clear the environment variables
351 oldVisual := os.Getenv("VISUAL")
352 oldEditor := os.Getenv("EDITOR")
353 defer func() {
354 os.Setenv("VISUAL", oldVisual)
355 os.Setenv("EDITOR", oldEditor)
356 }()
357
358 // with no env vars, the config file value should be used
359 os.Unsetenv("VISUAL")
360 os.Unsetenv("EDITOR")
361 conf, err := New(mocks.Path("conf/conf.yml"), false)
362 if err != nil {
363 t.Fatalf("failed to init configs: %v", err)
364 }
365 if conf.Editor != "vim" {
366 t.Errorf("expected config file editor: want: vim, got: %s", conf.Editor)
367 }
368
369 // $EDITOR should override the config file value
370 os.Setenv("EDITOR", "nano")
371 conf, err = New(mocks.Path("conf/conf.yml"), false)
372 if err != nil {
373 t.Fatalf("failed to init configs: %v", err)
374 }
375 if conf.Editor != "nano" {
376 t.Errorf("$EDITOR should override config: want: nano, got: %s", conf.Editor)
377 }
378
379 // $VISUAL should override both $EDITOR and the config file value
380 os.Setenv("VISUAL", "emacs")
381 conf, err = New(mocks.Path("conf/conf.yml"), false)
382 if err != nil {
383 t.Fatalf("failed to init configs: %v", err)
384 }
385 if conf.Editor != "emacs" {
386 t.Errorf("$VISUAL should override all: want: emacs, got: %s", conf.Editor)
387 }
388}
389
390// TestEditorEnvFallback asserts that env vars are used as fallback when
391// no editor is specified in the config file

Callers

nothing calls this directly

Calls 2

PathFunction · 0.92
NewFunction · 0.70

Tested by

no test coverage detected