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

Function TestConfigFile_GlobalLevel

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

Source from the content-addressed store, hash-verified

90}
91
92func TestConfigFile_GlobalLevel(t *testing.T) {
93 resetViper()
94 resetFlags()
95 defer resetViper()
96 defer resetFlags()
97
98 // Create a temporary home directory with config
99 homeDir := t.TempDir()
100 createConfigFile(t, homeDir, `
101dir: ./global-tasks
102verbose: true
103`)
104
105 // Set HOME to temp directory
106 origHome := os.Getenv("HOME")
107 os.Setenv("HOME", homeDir)
108 defer os.Setenv("HOME", origHome)
109
110 // Create a different working directory without config
111 workDir := t.TempDir()
112 origDir, _ := os.Getwd()
113 defer os.Chdir(origDir)
114 if err := os.Chdir(workDir); err != nil {
115 t.Fatalf("failed to change directory: %v", err)
116 }
117
118 // Re-initialize cobra command
119 rootCmd = &cobra.Command{Use: "taskmd"}
120 cobra.OnInitialize(initConfig)
121 rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file")
122 rootCmd.PersistentFlags().BoolVar(&stdin, "stdin", false, "read from stdin")
123 rootCmd.PersistentFlags().BoolVarP(&quiet, "quiet", "q", false, "quiet mode")
124 rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose logging")
125 rootCmd.PersistentFlags().StringVarP(&taskDir, "task-dir", "d", ".", "task directory")
126
127 // Bind flags to viper
128 viper.BindPFlag("stdin", rootCmd.PersistentFlags().Lookup("stdin"))
129 viper.BindPFlag("quiet", rootCmd.PersistentFlags().Lookup("quiet"))
130 viper.BindPFlag("verbose", rootCmd.PersistentFlags().Lookup("verbose"))
131 viper.BindPFlag("task-dir", rootCmd.PersistentFlags().Lookup("task-dir"))
132
133 // Initialize config
134 initConfig()
135
136 // Test that global config values are loaded
137 flags := GetGlobalFlags()
138 expectedDir := filepath.Join(homeDir, "global-tasks")
139 if flags.TaskDir != expectedDir {
140 t.Errorf("expected dir to be %q, got %q", expectedDir, flags.TaskDir)
141 }
142 if !flags.Verbose {
143 t.Error("expected verbose to be true from global config")
144 }
145}
146
147func TestConfigFile_Precedence_ProjectOverGlobal(t *testing.T) {
148 resetViper()

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected