Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func Test_CreateApp(t *testing.T) {
},
cmd: &cli.Options{
Type: cli.CommandRun,
Profile: config.DefaultProfile,
Profile: config.Default,
NoUI: false,
},
},
Expand All @@ -60,7 +60,7 @@ func Test_CreateApp(t *testing.T) {
},
cmd: &cli.Options{
Type: cli.CommandRun,
Profile: config.DefaultProfile,
Profile: config.Default,
NoUI: true,
},
},
Expand All @@ -76,7 +76,7 @@ func Test_CreateApp(t *testing.T) {
},
cmd: &cli.Options{
Type: cli.CommandRun,
Profile: config.DefaultProfile,
Profile: config.Default,
NoUI: false,
},
},
Expand Down
10 changes: 5 additions & 5 deletions internal/app/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/app/cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Options struct {
func Parse(args []string) (*Options, error) {
result := &Options{
Type: CommandRun,
Profile: config.DefaultProfile,
Profile: config.Default,
}

var (
Expand Down
18 changes: 9 additions & 9 deletions internal/app/cli/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
{
Expand Down Expand Up @@ -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,
},
{
Expand Down Expand Up @@ -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,
},
}
Expand Down
14 changes: 8 additions & 6 deletions internal/app/runner/workerpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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):
}

Expand All @@ -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()
}
}
Expand Down Expand Up @@ -91,15 +93,15 @@ 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)
}

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)
}
Expand All @@ -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()
}
}
6 changes: 3 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
37 changes: 20 additions & 17 deletions internal/config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-"
Expand Down