diff --git a/cmd/main_test.go b/cmd/main_test.go index 3f1307d..fe87c74 100644 --- a/cmd/main_test.go +++ b/cmd/main_test.go @@ -44,7 +44,7 @@ func Test_CreateApp(t *testing.T) { }, cmd: &cli.Options{ Type: cli.CommandRun, - Profile: config.DefaultProfile, + Profile: config.Default, NoUI: false, }, }, @@ -60,7 +60,7 @@ func Test_CreateApp(t *testing.T) { }, cmd: &cli.Options{ Type: cli.CommandRun, - Profile: config.DefaultProfile, + Profile: config.Default, NoUI: true, }, }, @@ -76,7 +76,7 @@ func Test_CreateApp(t *testing.T) { }, cmd: &cli.Options{ Type: cli.CommandRun, - Profile: config.DefaultProfile, + Profile: config.Default, NoUI: false, }, }, diff --git a/internal/app/cli/cli_test.go b/internal/app/cli/cli_test.go index ce34ba6..28e4f37 100644 --- a/internal/app/cli/cli_test.go +++ b/internal/app/cli/cli_test.go @@ -24,7 +24,7 @@ func Test_NewCLI(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - cmd := &Options{Type: CommandRun, Profile: config.DefaultProfile, NoUI: true} + cmd := &Options{Type: CommandRun, Profile: config.Default, NoUI: true} mockRunner := runner.NewMockRunner(ctrl) mockLogsRunner := logs.NewMockRunner(ctrl) mockUI := func(ctx context.Context, profile string) (*tea.Program, error) { @@ -68,12 +68,12 @@ func Test_Execute(t *testing.T) { name: "Run command with default profile and --no-ui", cmd: &Options{ Type: CommandRun, - Profile: config.DefaultProfile, + Profile: config.Default, NoUI: true, }, before: func() { mockLogger.EXPECT().Debug().Return(nil) - mockRunner.EXPECT().Run(gomock.AssignableToTypeOf(context.Background()), config.DefaultProfile).Return(nil) + mockRunner.EXPECT().Run(gomock.AssignableToTypeOf(context.Background()), config.Default).Return(nil) }, expectedExit: 0, expectedError: false, @@ -82,7 +82,7 @@ func Test_Execute(t *testing.T) { name: "Help command", cmd: &Options{ Type: CommandHelp, - Profile: config.DefaultProfile, + Profile: config.Default, }, before: func() { mockLogger.EXPECT().Debug().Return(nil) @@ -94,7 +94,7 @@ func Test_Execute(t *testing.T) { name: "Version command", cmd: &Options{ Type: CommandVersion, - Profile: config.DefaultProfile, + Profile: config.Default, }, before: func() { mockLogger.EXPECT().Debug().Return(nil) diff --git a/internal/app/cli/commands.go b/internal/app/cli/commands.go index c077ac8..ac0d34d 100644 --- a/internal/app/cli/commands.go +++ b/internal/app/cli/commands.go @@ -29,7 +29,7 @@ type Options struct { func Parse(args []string) (*Options, error) { result := &Options{ Type: CommandRun, - Profile: config.DefaultProfile, + Profile: config.Default, } var ( diff --git a/internal/app/cli/commands_test.go b/internal/app/cli/commands_test.go index 5502beb..c2542ed 100644 --- a/internal/app/cli/commands_test.go +++ b/internal/app/cli/commands_test.go @@ -21,14 +21,14 @@ func Test_Parse(t *testing.T) { name: "no args - default profile", args: []string{}, expectedType: CommandRun, - expectedProfile: config.DefaultProfile, + expectedProfile: config.Default, expectedNoUI: false, }, { name: "run command without profile", args: []string{"run"}, expectedType: CommandRun, - expectedProfile: config.DefaultProfile, + expectedProfile: config.Default, expectedNoUI: false, }, { @@ -84,7 +84,7 @@ func Test_Parse(t *testing.T) { name: "--no-ui flag with no command", args: []string{"--no-ui"}, expectedType: CommandRun, - expectedProfile: config.DefaultProfile, + expectedProfile: config.Default, expectedNoUI: true, }, { @@ -139,42 +139,42 @@ func Test_Parse(t *testing.T) { name: "version command", args: []string{"version"}, expectedType: CommandVersion, - expectedProfile: config.DefaultProfile, + expectedProfile: config.Default, expectedNoUI: false, }, { name: "--version flag", args: []string{"--version"}, expectedType: CommandVersion, - expectedProfile: config.DefaultProfile, + expectedProfile: config.Default, expectedNoUI: false, }, { name: "-v flag", args: []string{"-v"}, expectedType: CommandVersion, - expectedProfile: config.DefaultProfile, + expectedProfile: config.Default, expectedNoUI: false, }, { name: "help command", args: []string{"help"}, expectedType: CommandHelp, - expectedProfile: config.DefaultProfile, + expectedProfile: config.Default, expectedNoUI: false, }, { name: "--help flag", args: []string{"--help"}, expectedType: CommandHelp, - expectedProfile: config.DefaultProfile, + expectedProfile: config.Default, expectedNoUI: false, }, { name: "-h flag", args: []string{"-h"}, expectedType: CommandHelp, - expectedProfile: config.DefaultProfile, + expectedProfile: config.Default, expectedNoUI: false, }, } diff --git a/internal/app/runner/workerpool_test.go b/internal/app/runner/workerpool_test.go index c20a830..e67af9c 100644 --- a/internal/app/runner/workerpool_test.go +++ b/internal/app/runner/workerpool_test.go @@ -8,13 +8,15 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "fuku/internal/config" ) func Test_AcquireRelease(t *testing.T) { pool := NewWorkerPool() ctx := context.Background() - for i := 0; i < 3; i++ { + for i := 0; i < config.MaxWorkers; i++ { err := pool.Acquire(ctx) require.NoError(t, err) } @@ -30,7 +32,7 @@ func Test_AcquireRelease(t *testing.T) { select { case <-done: - t.Fatal("Should not have acquired fourth worker slot immediately") + t.Fatal("Should not have acquired extra worker slot immediately") case <-time.After(50 * time.Millisecond): } @@ -42,7 +44,7 @@ func Test_AcquireRelease(t *testing.T) { t.Fatal("Should have acquired worker slot after release") } - for i := 0; i < 3; i++ { + for i := 0; i < config.MaxWorkers; i++ { pool.Release() } } @@ -91,7 +93,7 @@ func Test_ConcurrentWorkers(t *testing.T) { wg.Wait() assert.Equal(t, 0, activeWorkers) - assert.LessOrEqual(t, maxActive, 3) + assert.LessOrEqual(t, maxActive, config.MaxWorkers) assert.Greater(t, maxActive, 0) } @@ -99,7 +101,7 @@ func Test_AcquireContextCancelled(t *testing.T) { ctx := context.Background() pool := NewWorkerPool() - for i := 0; i < 3; i++ { + for i := 0; i < config.MaxWorkers; i++ { err := pool.Acquire(ctx) require.NoError(t, err) } @@ -123,7 +125,7 @@ func Test_AcquireContextCancelled(t *testing.T) { t.Fatal("Should have received context cancellation error") } - for i := 0; i < 3; i++ { + for i := 0; i < config.MaxWorkers; i++ { pool.Release() } } diff --git a/internal/config/config.go b/internal/config/config.go index 201d196..006c744 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -64,9 +64,9 @@ func DefaultConfig() *Config { Version: 1, } - cfg.Logging.Level = DefaultLogLevel - cfg.Logging.Format = DefaultLogFormat - cfg.Profiles[DefaultProfile] = "*" + cfg.Logging.Level = LogLevel + cfg.Logging.Format = LogFormat + cfg.Profiles[Default] = "*" return cfg } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 8c396d6..5f9581d 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -14,8 +14,8 @@ func Test_DefaultConfig(t *testing.T) { assert.NotNil(t, cfg.Services) assert.NotNil(t, cfg.Profiles) - assert.Equal(t, DefaultLogLevel, cfg.Logging.Level) - assert.Equal(t, DefaultLogFormat, cfg.Logging.Format) + assert.Equal(t, LogLevel, cfg.Logging.Level) + assert.Equal(t, LogFormat, cfg.Logging.Format) assert.Equal(t, 1, cfg.Version) } diff --git a/internal/config/constants.go b/internal/config/constants.go index 7177513..d9b37e1 100644 --- a/internal/config/constants.go +++ b/internal/config/constants.go @@ -2,45 +2,48 @@ package config import "time" -// app constants +// Application metadata const ( AppName = "fuku" - - DefaultLogLevel = "info" - DefaultLogFormat = "console" - Version = "0.9.1" ) -// profile constants +// Default values const ( - DefaultProfile = "default" + Default = "default" ) -// tier constants +// Logging defaults const ( - Default = "default" - MaxWorkers = 3 + LogLevel = "info" + LogFormat = "console" ) -// readiness constants +// Concurrency settings +const ( + MaxWorkers = 5 +) + +// Readiness check types const ( TypeHTTP = "http" TypeLog = "log" +) +// Timing constants +const ( DefaultTimeout = 30 * time.Second DefaultInterval = 500 * time.Millisecond - - RetryAttempt = 3 - RetryBackoff = 500 * time.Millisecond + ShutdownTimeout = 5 * time.Second ) -// service constants +// Retry settings const ( - ShutdownTimeout = 5 * time.Second + RetryAttempt = 3 + RetryBackoff = 500 * time.Millisecond ) -// socket constants +// Socket configuration const ( SocketDir = "/tmp" SocketPrefix = "fuku-"