diff options
Diffstat (limited to 'internal/config')
| -rw-r--r-- | internal/config/config.go | 10 | ||||
| -rw-r--r-- | internal/config/config_test.go | 37 |
2 files changed, 44 insertions, 3 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 036d081..d53fd7f 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -24,8 +24,9 @@ type Config struct { MaxWidth int NetAverage int NetLink string - ShowAvgLine bool - ShowCores bool + ShowAvgLine bool + ShowIOAvgLine bool + ShowCores bool ShowMem bool ShowNet bool SSHOpts string @@ -105,7 +106,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, - "showavgline": true, "shownet": true, "sshopts": true, "cluster": true, + "showavgline": true, "showioavgline": true, "shownet": true, "sshopts": true, "cluster": true, } scanner := bufio.NewScanner(f) for scanner.Scan() { @@ -162,6 +163,8 @@ func (c *Config) set(key, val string) { c.NetLink = val case "showavgline": c.ShowAvgLine = parseBool(val) + case "showioavgline": + c.ShowIOAvgLine = parseBool(val) case "showcores": c.ShowCores = parseBool(val) case "showmem": @@ -200,6 +203,7 @@ func (c *Config) writeTo(f *os.File) error { writeInt("netaverage", c.NetAverage) writeStr("netlink", c.NetLink) writeBool("showavgline", c.ShowAvgLine) + writeBool("showioavgline", c.ShowIOAvgLine) 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 db0e068..a8535be 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -115,6 +115,43 @@ func TestConfig_showAvgLineRoundTrip(t *testing.T) { } } +func TestConfig_showIOAvgLineRoundTrip(t *testing.T) { + // Write a config with showioavgline=1, read it back, verify round-trip + c := Default() + c.ShowIOAvgLine = 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("showioavgline=1")) { + t.Errorf("expected showioavgline=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.ShowIOAvgLine { + t.Error("expected ShowIOAvgLine=true after round-trip") + } +} + func TestGetClusterHostsFromFile(t *testing.T) { dir := t.TempDir() path := filepath.Join(dir, "clusters") |
