MCPcopy Create free account
hub / github.com/driangle/taskmd / TestConfigFile_Defaults

Function TestConfigFile_Defaults

apps/cli/internal/cli/config_test.go:313–359  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

311}
312
313func TestConfigFile_Defaults(t *testing.T) {
314 resetViper()
315 resetFlags()
316 defer resetViper()
317 defer resetFlags()
318
319 // Create empty temp directory (no config file)
320 workDir := t.TempDir()
321 origDir, _ := os.Getwd()
322 defer os.Chdir(origDir)
323 if err := os.Chdir(workDir); err != nil {
324 t.Fatalf("failed to change directory: %v", err)
325 }
326
327 // Set HOME to directory without config
328 homeDir := t.TempDir()
329 origHome := os.Getenv("HOME")
330 os.Setenv("HOME", homeDir)
331 defer os.Setenv("HOME", origHome)
332
333 // Re-initialize cobra command
334 rootCmd = &cobra.Command{Use: "taskmd"}
335 cobra.OnInitialize(initConfig)
336 rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file")
337 rootCmd.PersistentFlags().BoolVar(&stdin, "stdin", false, "read from stdin")
338 rootCmd.PersistentFlags().BoolVarP(&quiet, "quiet", "q", false, "quiet mode")
339 rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose logging")
340 rootCmd.PersistentFlags().StringVarP(&taskDir, "task-dir", "d", ".", "task directory")
341
342 // Bind flags to viper
343 viper.BindPFlag("stdin", rootCmd.PersistentFlags().Lookup("stdin"))
344 viper.BindPFlag("quiet", rootCmd.PersistentFlags().Lookup("quiet"))
345 viper.BindPFlag("verbose", rootCmd.PersistentFlags().Lookup("verbose"))
346 viper.BindPFlag("task-dir", rootCmd.PersistentFlags().Lookup("task-dir"))
347
348 // Initialize config (no config file found)
349 initConfig()
350
351 // Test that defaults are used
352 flags := GetGlobalFlags()
353 if flags.TaskDir != "." {
354 t.Errorf("expected default dir '.', got '%s'", flags.TaskDir)
355 }
356 if flags.Verbose {
357 t.Error("expected default verbose to be false")
358 }
359}
360
361func TestConfigFile_ExplicitConfigFile(t *testing.T) {
362 resetViper()

Callers

nothing calls this directly

Calls 5

resetViperFunction · 0.85
resetFlagsFunction · 0.85
initConfigFunction · 0.85
GetGlobalFlagsFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected