diff options
Diffstat (limited to 'internal/config')
| -rw-r--r-- | internal/config/config.go | 12 | ||||
| -rw-r--r-- | internal/config/config_test.go | 37 |
2 files changed, 45 insertions, 4 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 0fc80d4..036d081 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -24,9 +24,10 @@ type Config struct { MaxWidth int NetAverage int NetLink string - ShowCores bool - ShowMem bool - ShowNet bool + ShowAvgLine bool + ShowCores bool + ShowMem bool + ShowNet bool SSHOpts string Cluster string } @@ -104,7 +105,7 @@ func (c *Config) parseReader(f *os.File) error { "title": true, "barwidth": true, "cpuaverage": true, "extended": true, "hasagent": true, "height": true, "maxwidth": true, "netaverage": true, "netlink": true, "showcores": true, "showmem": true, - "shownet": true, "sshopts": true, "cluster": true, + "showavgline": true, "shownet": true, "sshopts": true, "cluster": true, } scanner := bufio.NewScanner(f) for scanner.Scan() { @@ -159,6 +160,8 @@ func (c *Config) set(key, val string) { } case "netlink": c.NetLink = val + case "showavgline": + c.ShowAvgLine = parseBool(val) case "showcores": c.ShowCores = parseBool(val) case "showmem": @@ -196,6 +199,7 @@ func (c *Config) writeTo(f *os.File) error { writeInt("maxwidth", c.MaxWidth) writeInt("netaverage", c.NetAverage) writeStr("netlink", c.NetLink) + writeBool("showavgline", c.ShowAvgLine) writeBool("showcores", c.ShowCores) writeBool("showmem", c.ShowMem) writeBool("shownet", c.ShowNet) diff --git a/internal/config/config_test.go b/internal/config/config_test.go index dfa499c..db0e068 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -78,6 +78,43 @@ func TestConfig_writeTo(t *testing.T) { } } +func TestConfig_showAvgLineRoundTrip(t *testing.T) { + // Write a config with showavgline=1, read it back, verify round-trip + c := Default() + c.ShowAvgLine = true + + dir := t.TempDir() + path := filepath.Join(dir, "rc") + f, err := os.Create(path) + if err != nil { + t.Fatal(err) + } + if err := c.writeTo(f); err != nil { + f.Close() + t.Fatal(err) + } + f.Close() + + data, _ := os.ReadFile(path) + if !bytes.Contains(data, []byte("showavgline=1")) { + t.Errorf("expected showavgline=1 in output, got:\n%s", data) + } + + // Read it back + c2 := Default() + f2, err := os.Open(path) + if err != nil { + t.Fatal(err) + } + defer f2.Close() + if err := c2.parseReader(f2); err != nil { + t.Fatal(err) + } + if !c2.ShowAvgLine { + t.Error("expected ShowAvgLine=true after round-trip") + } +} + func TestGetClusterHostsFromFile(t *testing.T) { dir := t.TempDir() path := filepath.Join(dir, "clusters") |
