Skip to content

Comments

feat: add and test default values for API and logging configuration#861

Merged
appleboy merged 3 commits intomasterfrom
config
Jan 4, 2026
Merged

feat: add and test default values for API and logging configuration#861
appleboy merged 3 commits intomasterfrom
config

Conversation

@appleboy
Copy link
Owner

@appleboy appleboy commented Jan 4, 2026

  • Add default values for API endpoints in configuration
  • Add default values for logging format, output, levels, and log token/message settings
  • Add tests to verify API and log configuration defaults and their override via environment variables
  • Improve tests to ensure config defaults are restored after modification
  • Add test coverage for logging config fallback to defaults when not specified
  • Add test to confirm all API endpoints have defined default values

fix #854

- Add default values for API endpoints in configuration
- Add default values for logging format, output, levels, and log token/message settings
- Add tests to verify API and log configuration defaults and their override via environment variables
- Improve tests to ensure config defaults are restored after modification
- Add test coverage for logging config fallback to defaults when not specified
- Add test to confirm all API endpoints have defined default values

fix #854

Signed-off-by: appleboy <appleboy.tw@gmail.com>
Copilot AI review requested due to automatic review settings January 4, 2026 04:42
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds default values for API endpoints and logging configuration to fix issue #854, where missing defaults could cause initialization failures. The changes ensure that all API endpoints and logging settings have proper fallback values.

Key Changes

  • Added default values in setDefaults() for 7 API endpoints (push, stat_go, stat_app, config, sys_stat, metric, health URIs)
  • Added default values for logging configuration (format, access_log, access_level, error_log, error_level, hide_token, hide_messages)
  • Added comprehensive test coverage to verify defaults work correctly and can be overridden via environment variables

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
config/config.go Adds viper.SetDefault() calls for API endpoints and logging configuration to ensure defaults are always available
config/config_test.go Adds backup/restore logic for TestLoadWrongDefaultYAMLConfig and four new test functions to verify API/logging defaults and environment variable overrides

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Update tests to use Platform constants' String method instead of hardcoded strings
- Refactor test input for marshaling and unmarshaling to use dynamic string values from Platform constants
- Improve JSON marshaling test to compare with dynamically generated expected output

Signed-off-by: appleboy <appleboy.tw@gmail.com>
…ests

- Switch to using t.Cleanup for environment variable cleanup in tests
- Remove manual os.Unsetenv calls at the end of test functions
- Improve test reliability by ensuring proper cleanup even on failure

Signed-off-by: appleboy <appleboy.tw@gmail.com>
@appleboy appleboy merged commit 4ef067e into master Jan 4, 2026
12 of 13 checks passed
@appleboy appleboy deleted the config branch January 4, 2026 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

panic in running job: handlers are already registered for path '/'

1 participant