Refactor for readability
This commit is contained in:
1 parent
ff9860023b
commit
17baba1490
11 files changed
+536
-405
No files matched your search
@@ -0,0 +1,27 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
path := t.TempDir() + "/config.json"
|
||||
if err := os.WriteFile(path, []byte(`{"write_secret":"secret","addr":":9090","chart_max_watts":750}`), 0o600); err != nil {
|
||||
t.Fatalf("write config: %v", err)
|
||||
}
|
||||
|
||||
cfg, err := Load(path)
|
||||
if err != nil {
|
||||
t.Fatalf("Load returned error: %v", err)
|
||||
}
|
||||
if cfg.WriteSecret != "secret" {
|
||||
t.Fatalf("write_secret = %q, want %q", cfg.WriteSecret, "secret")
|
||||
}
|
||||
if cfg.Addr != ":9090" {
|
||||
t.Fatalf("addr = %q, want %q", cfg.Addr, ":9090")
|
||||
}
|
||||
if cfg.ChartMaxWatts != 750 {
|
||||
t.Fatalf("chart_max_watts = %d, want %d", cfg.ChartMaxWatts, 750)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user