(t *testing.T)
| 258 | } |
| 259 | |
| 260 | func TestConfigFile_WebOptions(t *testing.T) { |
| 261 | resetViper() |
| 262 | resetFlags() |
| 263 | defer resetViper() |
| 264 | defer resetFlags() |
| 265 | |
| 266 | // Create project config with web options |
| 267 | projectDir := t.TempDir() |
| 268 | createConfigFile(t, projectDir, ` |
| 269 | web: |
| 270 | port: 3000 |
| 271 | auto_open_browser: true |
| 272 | `) |
| 273 | |
| 274 | origDir, _ := os.Getwd() |
| 275 | defer os.Chdir(origDir) |
| 276 | if err := os.Chdir(projectDir); err != nil { |
| 277 | t.Fatalf("failed to change directory: %v", err) |
| 278 | } |
| 279 | |
| 280 | // Re-initialize cobra command |
| 281 | rootCmd = &cobra.Command{Use: "taskmd"} |
| 282 | webCmd = &cobra.Command{Use: "web"} |
| 283 | webStartCmd = &cobra.Command{Use: "start"} |
| 284 | rootCmd.AddCommand(webCmd) |
| 285 | webCmd.AddCommand(webStartCmd) |
| 286 | |
| 287 | cobra.OnInitialize(initConfig) |
| 288 | |
| 289 | // Setup web flags |
| 290 | webStartCmd.Flags().IntVar(&webPort, "port", 8080, "server port") |
| 291 | webStartCmd.Flags().BoolVar(&webDev, "dev", false, "enable dev mode") |
| 292 | webStartCmd.Flags().BoolVar(&webOpen, "open", false, "open browser on start") |
| 293 | |
| 294 | // Bind web flags to viper |
| 295 | viper.BindPFlag("web.port", webStartCmd.Flags().Lookup("port")) |
| 296 | viper.BindPFlag("web.auto_open_browser", webStartCmd.Flags().Lookup("open")) |
| 297 | |
| 298 | // Initialize config |
| 299 | initConfig() |
| 300 | |
| 301 | // Test that web config values are loaded |
| 302 | port := viper.GetInt("web.port") |
| 303 | open := viper.GetBool("web.auto_open_browser") |
| 304 | |
| 305 | if port != 3000 { |
| 306 | t.Errorf("expected web.port to be 3000, got %d", port) |
| 307 | } |
| 308 | if !open { |
| 309 | t.Error("expected web.auto_open_browser to be true from config") |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | func TestConfigFile_Defaults(t *testing.T) { |
| 314 | resetViper() |
nothing calls this directly
no test coverage detected