kubo/plugin/plugins/peerlog/peerlog_test.go
Marcin Rataj 6a008fc74c
refactor: apply go fix modernizers from Go 1.26 (#11190)
* chore: apply go fix modernizers from Go 1.26

automated refactoring: interface{} to any, slices.Contains,
and other idiomatic updates.

* feat(ci): add `go fix` check to Go analysis workflow

ensures Go 1.26 modernizers are applied, fails CI if `go fix ./...`
produces any changes (similar to existing `go fmt` enforcement)
2026-02-11 01:01:32 +01:00

50 lines
1.1 KiB
Go

package peerlog
import "testing"
func TestExtractEnabled(t *testing.T) {
for _, c := range []struct {
name string
config any
expected bool
}{
{
name: "nil config returns false",
config: nil,
expected: false,
},
{
name: "returns false when config is not a string map",
config: 1,
expected: false,
},
{
name: "returns false when config has no Enabled field",
config: map[string]any{},
expected: false,
},
{
name: "returns false when config has a null Enabled field",
config: map[string]any{"Enabled": nil},
expected: false,
},
{
name: "returns false when config has a non-boolean Enabled field",
config: map[string]any{"Enabled": 1},
expected: false,
},
{
name: "returns the value of the Enabled field",
config: map[string]any{"Enabled": true},
expected: true,
},
} {
t.Run(c.name, func(t *testing.T) {
isEnabled := extractEnabled(c.config)
if isEnabled != c.expected {
t.Fatalf("expected %v, got %v", c.expected, isEnabled)
}
})
}
}