Adopt repo standards: scaffold, policies, lint-clean (closes #1)
check / check (push) Failing after 1s
check / check (push) Failing after 1s
Add the standard scaffold and bring the tree to a clean lint under the vendored `default: all` config. New: `script/` Scripts-to-Rule-Them-All entrypoints with the `Makefile` reduced to thin shims; a `Dockerfile` whose `lint` and `test` phases gate the build (final stage depends on both); a `.gitea/workflows/` CI running `script/cibuild`; the vendored `.golangci.yml`; `REPO_POLICIES.md`; `.editorconfig`; `.dockerignore`; a `LICENSE` (WTFPL) and `TODO.md`; and a comprehensive `.gitignore`. The 211 lint findings were fixed, not suppressed: package-level state became functions/fields/a command constructor, magic numbers became named constants, `ctx` is threaded into the probes, the loop functions were split to cut complexity, and the deprecated `+build` tags were dropped. Behavior is unchanged. The only annotations are justified `//nolint:gosec` on the `ping`/`curl` subprocess calls (G204, fixed argv) and the operator-chosen log file (G304), matching the reference repos. `make check` is green (lint and tests run in Docker). Model: opus-4-8
This commit is contained in:
@@ -1,104 +1,48 @@
|
||||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
package monitor
|
||||
package monitor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
tcell "github.com/gdamore/tcell/v2"
|
||||
|
||||
"git.eeqj.de/sneak/rtnetmon/internal/monitor"
|
||||
)
|
||||
|
||||
// TestMeterColorForValue tests the MeterColorForValue function
|
||||
func TestMeterColorForValue(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
value int
|
||||
maxValue int
|
||||
reverse bool
|
||||
wantColor tcell.Style
|
||||
}{
|
||||
// Reverse mode tests (low is good, high is bad)
|
||||
{
|
||||
name: "reverse mode: 0% (best)",
|
||||
value: 0,
|
||||
maxValue: 10,
|
||||
reverse: true,
|
||||
wantColor: CBrightGreen,
|
||||
},
|
||||
{
|
||||
name: "reverse mode: 10% (good)",
|
||||
value: 1,
|
||||
maxValue: 10,
|
||||
reverse: true,
|
||||
wantColor: CBrightGreen,
|
||||
},
|
||||
{
|
||||
name: "reverse mode: 50% (medium)",
|
||||
value: 5,
|
||||
maxValue: 10,
|
||||
reverse: true,
|
||||
wantColor: CYellow,
|
||||
},
|
||||
{
|
||||
name: "reverse mode: 90% (bad)",
|
||||
value: 9,
|
||||
maxValue: 10,
|
||||
reverse: true,
|
||||
wantColor: CRed,
|
||||
},
|
||||
{
|
||||
name: "reverse mode: 100% (worst)",
|
||||
value: 10,
|
||||
maxValue: 10,
|
||||
reverse: true,
|
||||
wantColor: CRed,
|
||||
},
|
||||
t.Parallel()
|
||||
|
||||
// Normal mode tests (high is good, low is bad)
|
||||
{
|
||||
name: "normal mode: 0% (worst)",
|
||||
value: 0,
|
||||
maxValue: 10,
|
||||
reverse: false,
|
||||
wantColor: CRed,
|
||||
},
|
||||
{
|
||||
name: "normal mode: 10% (bad)",
|
||||
value: 1,
|
||||
maxValue: 10,
|
||||
reverse: false,
|
||||
wantColor: CRed,
|
||||
},
|
||||
{
|
||||
name: "normal mode: 50% (medium)",
|
||||
value: 5,
|
||||
maxValue: 10,
|
||||
reverse: false,
|
||||
wantColor: CYellow,
|
||||
},
|
||||
{
|
||||
name: "normal mode: 90% (good)",
|
||||
value: 9,
|
||||
maxValue: 10,
|
||||
reverse: false,
|
||||
wantColor: CBrightGreen,
|
||||
},
|
||||
{
|
||||
name: "normal mode: 100% (best)",
|
||||
value: 10,
|
||||
maxValue: 10,
|
||||
reverse: false,
|
||||
wantColor: CBrightGreen,
|
||||
},
|
||||
green := tcell.StyleDefault.Foreground(tcell.ColorGreen).Bold(true)
|
||||
yellow := tcell.StyleDefault.Foreground(tcell.ColorYellow)
|
||||
red := tcell.StyleDefault.Foreground(tcell.ColorRed)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
value, maxValue int
|
||||
reverse bool
|
||||
want tcell.Style
|
||||
}{
|
||||
{"reverse 0% best", 0, 10, true, green},
|
||||
{"reverse 10% good", 1, 10, true, green},
|
||||
{"reverse 50% medium", 5, 10, true, yellow},
|
||||
{"reverse 90% bad", 9, 10, true, red},
|
||||
{"reverse 100% worst", 10, 10, true, red},
|
||||
{"normal 0% worst", 0, 10, false, red},
|
||||
{"normal 10% bad", 1, 10, false, red},
|
||||
{"normal 50% medium", 5, 10, false, yellow},
|
||||
{"normal 90% good", 9, 10, false, green},
|
||||
{"normal 100% best", 10, 10, false, green},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := MeterColorForValue(tt.value, tt.maxValue, tt.reverse)
|
||||
if got != tt.wantColor {
|
||||
t.Parallel()
|
||||
|
||||
got := monitor.MeterColorForValue(tt.value, tt.maxValue, tt.reverse)
|
||||
if got != tt.want {
|
||||
t.Errorf("MeterColorForValue(%d, %d, %v) = %v, want %v",
|
||||
tt.value, tt.maxValue, tt.reverse, got, tt.wantColor)
|
||||
tt.value, tt.maxValue, tt.reverse, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user