Skip to content

Commit c3f73e5

Browse files
committed
Test fixes
1 parent 3abb289 commit c3f73e5

File tree

1 file changed

+1
-100
lines changed

1 file changed

+1
-100
lines changed

pkg/config/config_test.go

Lines changed: 1 addition & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import (
77

88
"github.com/BurntSushi/toml"
99
"github.com/stretchr/testify/assert"
10-
"github.com/urfave/cli/v2"
1110

12-
"github.com/rubiojr/hashup/internal/config"
11+
"github.com/rubiojr/hashup/pkg/config"
1312
)
1413

1514
func TestDefaultConfig(t *testing.T) {
@@ -97,104 +96,6 @@ func TestSaveConfig(t *testing.T) {
9796
assert.Equal(t, "nats://customserver:4222", loadedCfg.Main.NatsServerURL)
9897
}
9998

100-
func TestLoadConfigFromCLI(t *testing.T) {
101-
t.Skip("broken")
102-
tempDir := t.TempDir()
103-
configPath := filepath.Join(tempDir, "cli_config.toml")
104-
105-
// Create a basic config file
106-
basicCfg := config.DefaultConfig()
107-
err := config.SaveConfig(basicCfg, configPath)
108-
assert.NoError(t, err)
109-
110-
tests := []struct {
111-
name string
112-
args []string
113-
validate func(*testing.T, *config.Config)
114-
}{
115-
{
116-
name: "Custom config file",
117-
args: []string{"--config", configPath},
118-
validate: func(t *testing.T, cfg *config.Config) {
119-
assert.Equal(t, configPath, cfg.Path)
120-
},
121-
},
122-
{
123-
name: "Custom encryption key",
124-
args: []string{"--config", configPath, "--encryption-key", "testkey123"},
125-
validate: func(t *testing.T, cfg *config.Config) {
126-
assert.Equal(t, "testkey123", cfg.Main.EncryptionKey)
127-
},
128-
},
129-
{
130-
name: "Custom DB path",
131-
args: []string{"--config", configPath, "--db-path", "/custom/db/path"},
132-
validate: func(t *testing.T, cfg *config.Config) {
133-
assert.Equal(t, "/custom/db/path", cfg.Store.DBPath)
134-
},
135-
},
136-
{
137-
name: "Custom stats interval",
138-
args: []string{"--config", configPath, "--stats-interval", "120"},
139-
validate: func(t *testing.T, cfg *config.Config) {
140-
assert.Equal(t, 120, cfg.Store.StatsInterval)
141-
},
142-
},
143-
{
144-
name: "Custom NATS URL",
145-
args: []string{"--config", configPath, "--nats-url", "nats://custom:4222"},
146-
validate: func(t *testing.T, cfg *config.Config) {
147-
assert.Equal(t, "nats://custom:4222", cfg.Main.NatsServerURL)
148-
},
149-
},
150-
}
151-
152-
for _, tt := range tests {
153-
t.Run(tt.name, func(t *testing.T) {
154-
app := cli.NewApp()
155-
ctx := cli.NewContext(app, nil, nil)
156-
157-
// Set up flags
158-
flags := map[string]any{
159-
"config": configPath,
160-
"encryption-key": "",
161-
"db-path": "",
162-
"stats-interval": 0,
163-
"nats-url": "",
164-
"stream": "",
165-
"client-cert": "",
166-
"client-key": "",
167-
"ca-cert": "",
168-
}
169-
170-
// Apply command line args
171-
for i := 0; i < len(tt.args); i += 2 {
172-
if i+1 < len(tt.args) {
173-
flagName := tt.args[i][2:] // Remove --
174-
flagValue := tt.args[i+1]
175-
flags[flagName] = flagValue
176-
}
177-
}
178-
179-
// Set values in the context
180-
for name, value := range flags {
181-
switch v := value.(type) {
182-
case string:
183-
ctx.Set(name, v)
184-
case int:
185-
if v != 0 {
186-
ctx.Set(name, string(rune(v)))
187-
}
188-
}
189-
}
190-
191-
cfg, err := config.LoadConfigFromCLI(ctx)
192-
assert.NoError(t, err)
193-
tt.validate(t, cfg)
194-
})
195-
}
196-
}
197-
19899
func TestDefaultPaths(t *testing.T) {
199100
homeDir, _ := os.UserHomeDir()
200101

0 commit comments

Comments
 (0)