Skip to content

Commit 750520d

Browse files
michaelmcneesclaude
andcommitted
fix: address PR review — paused container, quit option, dbdefaults in config, test names
- docker.go: handle "paused" container state in dockerStartPostgres - init.go: add q/quit/back escape from connection string prompt - config.go: build default DB URL from dbdefaults constants - loopback_test.go: add 127.0.0.2 case and named subtests Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4a13a4d commit 750520d

4 files changed

Lines changed: 20 additions & 12 deletions

File tree

internal/cli/docker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func dockerStartPostgres(cfg config.DatabaseConfig) error {
6868
case "running":
6969
// Already running — just wait for readiness.
7070
return waitForPostgres(cfg)
71-
case "exited", "created", "dead":
71+
case "exited", "created", "dead", "paused":
7272
_ = dockerRemoveContainer()
7373
}
7474

internal/cli/init.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ func promptConnectionString(cmd *cobra.Command, cfg *config.Config) (*sql.DB, er
139139
continue
140140
}
141141

142+
lower := strings.ToLower(connStr)
143+
if lower == "q" || lower == "quit" || lower == "back" {
144+
return nil, fmt.Errorf("connection string entry cancelled")
145+
}
146+
142147
cfg.Database.URL = connStr
143148
database, err := db.Open(cfg.Database)
144149
if err != nil {

internal/config/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/dvflw/mantle/internal/budget"
14+
"github.com/dvflw/mantle/internal/dbdefaults"
1415
"github.com/dvflw/mantle/internal/netutil"
1516
"github.com/spf13/cobra"
1617
"github.com/spf13/viper"
@@ -142,7 +143,7 @@ func Load(cmd *cobra.Command) (*Config, error) {
142143
v := viper.New()
143144

144145
// Defaults
145-
v.SetDefault("database.url", "postgres://mantle:mantle@localhost:5432/mantle?sslmode=prefer")
146+
v.SetDefault("database.url", fmt.Sprintf("postgres://%s:%s@localhost:5432/%s?sslmode=prefer", dbdefaults.User, dbdefaults.Password, dbdefaults.Database))
146147
v.SetDefault("database.max_open_conns", 25)
147148
v.SetDefault("database.max_idle_conns", 25)
148149
v.SetDefault("database.conn_max_lifetime", 5*time.Minute)

internal/netutil/loopback_test.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@ import (
99

1010
func TestIsLoopback(t *testing.T) {
1111
tests := []struct {
12+
name string
1213
host string
1314
expected bool
1415
}{
15-
{"localhost", true},
16-
{"LOCALHOST", true},
17-
{"Localhost", true},
18-
{"127.0.0.1", true},
19-
{"::1", true},
20-
{"db.example.com", false},
21-
{"10.0.0.1", false},
22-
{"192.168.1.1", false},
23-
{"", false},
16+
{"localhost", "localhost", true},
17+
{"localhost-upper", "LOCALHOST", true},
18+
{"localhost-mixed", "Localhost", true},
19+
{"ipv4-loopback", "127.0.0.1", true},
20+
{"ipv4-loopback-range", "127.0.0.2", true},
21+
{"ipv6-loopback", "::1", true},
22+
{"remote-host", "db.example.com", false},
23+
{"private-ipv4", "10.0.0.1", false},
24+
{"lan-ipv4", "192.168.1.1", false},
25+
{"empty", "", false},
2426
}
2527
for _, tt := range tests {
26-
t.Run(tt.host, func(t *testing.T) {
28+
t.Run(tt.name, func(t *testing.T) {
2729
assert.Equal(t, tt.expected, netutil.IsLoopback(tt.host))
2830
})
2931
}

0 commit comments

Comments
 (0)