Merge pull request 'golang-1-26' (#27) from golang-1-26 into main
Reviewed-on: https://git.iamthefij.com/iamthefij/minitor-go/pulls/27
This commit is contained in:
+9
-27
@@ -1,52 +1,34 @@
|
|||||||
version: "2"
|
version: "2"
|
||||||
linters:
|
linters:
|
||||||
enable:
|
enable:
|
||||||
|
- errcheck
|
||||||
- errname
|
- errname
|
||||||
- errorlint
|
- errorlint
|
||||||
- exhaustive
|
- exhaustive
|
||||||
- goprintffuncname
|
- gosec
|
||||||
|
- govet
|
||||||
|
- ineffassign
|
||||||
- misspell
|
- misspell
|
||||||
- mnd
|
- mnd
|
||||||
- tagliatelle
|
- modernize
|
||||||
|
- staticcheck
|
||||||
|
- tagalign
|
||||||
- testpackage
|
- testpackage
|
||||||
- thelper
|
- thelper
|
||||||
- tparallel
|
- tparallel
|
||||||
- unconvert
|
- unconvert
|
||||||
|
- unused
|
||||||
- wrapcheck
|
- wrapcheck
|
||||||
- wsl
|
- wsl_v5
|
||||||
disable:
|
|
||||||
- gochecknoglobals
|
|
||||||
settings:
|
|
||||||
gosec:
|
|
||||||
excludes:
|
|
||||||
- G204
|
|
||||||
tagliatelle:
|
|
||||||
case:
|
|
||||||
rules:
|
|
||||||
json: snake
|
|
||||||
yaml: snake
|
|
||||||
exclusions:
|
exclusions:
|
||||||
generated: lax
|
generated: lax
|
||||||
presets:
|
presets:
|
||||||
- comments
|
|
||||||
- common-false-positives
|
- common-false-positives
|
||||||
- legacy
|
|
||||||
- std-error-handling
|
|
||||||
rules:
|
rules:
|
||||||
- linters:
|
- linters:
|
||||||
- gosec
|
- gosec
|
||||||
path: _test\.go
|
path: _test\.go
|
||||||
paths:
|
|
||||||
- third_party$
|
|
||||||
- builtin$
|
|
||||||
- examples$
|
|
||||||
formatters:
|
formatters:
|
||||||
enable:
|
enable:
|
||||||
- gofumpt
|
- gofumpt
|
||||||
- goimports
|
- goimports
|
||||||
exclusions:
|
|
||||||
generated: lax
|
|
||||||
paths:
|
|
||||||
- third_party$
|
|
||||||
- builtin$
|
|
||||||
- examples$
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ repos:
|
|||||||
- id: end-of-file-fixer
|
- id: end-of-file-fixer
|
||||||
- id: check-merge-conflict
|
- id: check-merge-conflict
|
||||||
- repo: https://github.com/golangci/golangci-lint
|
- repo: https://github.com/golangci/golangci-lint
|
||||||
rev: v2.7.2
|
rev: v2.10.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: golangci-lint
|
- id: golangci-lint
|
||||||
- repo: https://github.com/hadolint/hadolint
|
- repo: https://github.com/hadolint/hadolint
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ func TestAlertValidate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
c := c
|
|
||||||
|
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
@@ -77,7 +76,6 @@ func TestAlertSend(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
c := c
|
|
||||||
|
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
@@ -123,7 +121,6 @@ func TestAlertBuildTemplate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
c := c
|
|
||||||
|
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|||||||
+2
-4
@@ -24,7 +24,6 @@ func TestLoadConfig(t *testing.T) {
|
|||||||
{"./test/valid-config.hcl", nil, "Valid config file"},
|
{"./test/valid-config.hcl", nil, "Valid config file"},
|
||||||
}
|
}
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
c := c
|
|
||||||
|
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
@@ -51,7 +50,7 @@ func TestDefaultConfig(t *testing.T) {
|
|||||||
m.Config{
|
m.Config{
|
||||||
CheckInterval: 1 * time.Second,
|
CheckInterval: 1 * time.Second,
|
||||||
DefaultAlertAfter: 2,
|
DefaultAlertAfter: 2,
|
||||||
DefaultAlertEvery: Ptr(0),
|
DefaultAlertEvery: new(0),
|
||||||
DefaultAlertDown: []string{"log_command"},
|
DefaultAlertDown: []string{"log_command"},
|
||||||
},
|
},
|
||||||
"override defaults",
|
"override defaults",
|
||||||
@@ -61,7 +60,7 @@ func TestDefaultConfig(t *testing.T) {
|
|||||||
m.Config{
|
m.Config{
|
||||||
CheckInterval: 30 * time.Second,
|
CheckInterval: 30 * time.Second,
|
||||||
DefaultAlertAfter: 1,
|
DefaultAlertAfter: 1,
|
||||||
DefaultAlertEvery: Ptr(-1),
|
DefaultAlertEvery: new(-1),
|
||||||
DefaultAlertDown: []string{},
|
DefaultAlertDown: []string{},
|
||||||
},
|
},
|
||||||
"default defaults",
|
"default defaults",
|
||||||
@@ -69,7 +68,6 @@ func TestDefaultConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
c := c
|
|
||||||
|
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module git.iamthefij.com/iamthefij/minitor-go/v2
|
module git.iamthefij.com/iamthefij/minitor-go/v2
|
||||||
|
|
||||||
go 1.25.0
|
go 1.26.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.iamthefij.com/iamthefij/slog/v2 v2.0.1
|
git.iamthefij.com/iamthefij/slog/v2 v2.0.1
|
||||||
|
|||||||
@@ -6,10 +6,6 @@ import (
|
|||||||
m "git.iamthefij.com/iamthefij/minitor-go/v2"
|
m "git.iamthefij.com/iamthefij/minitor-go/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Ptr[T any](v T) *T {
|
|
||||||
return &v
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestCheckConfig tests the checkConfig function
|
// TestCheckConfig tests the checkConfig function
|
||||||
// It also tests results for potentially invalid configuration. For example, no alerts
|
// It also tests results for potentially invalid configuration. For example, no alerts
|
||||||
func TestCheckMonitors(t *testing.T) {
|
func TestCheckMonitors(t *testing.T) {
|
||||||
@@ -91,7 +87,6 @@ func TestCheckMonitors(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
c := c
|
|
||||||
|
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
@@ -171,7 +166,6 @@ func TestFirstRunAlerts(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
c := c
|
|
||||||
|
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|||||||
+3
-8
@@ -25,7 +25,6 @@ func TestMonitorValidate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
c := c
|
|
||||||
|
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
@@ -103,7 +102,6 @@ func TestMonitorGetAlertNames(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
c := c
|
|
||||||
|
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
@@ -175,7 +173,6 @@ func TestMonitorFailureAlertAfter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
c := c
|
|
||||||
|
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
@@ -204,15 +201,14 @@ func TestMonitorFailureAlertEvery(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{m.Monitor{ShellCommand: "false", AlertAfter: 1}, []bool{true}, "No AlertEvery set"}, // Defaults to true because AlertAfter and AlertEvery default to nil
|
{m.Monitor{ShellCommand: "false", AlertAfter: 1}, []bool{true}, "No AlertEvery set"}, // Defaults to true because AlertAfter and AlertEvery default to nil
|
||||||
// Alert first time only, after 1
|
// Alert first time only, after 1
|
||||||
{m.Monitor{ShellCommand: "false", AlertAfter: 1, AlertEvery: Ptr(0)}, []bool{true, false, false}, "Alert first time only after 1"},
|
{m.Monitor{ShellCommand: "false", AlertAfter: 1, AlertEvery: new(0)}, []bool{true, false, false}, "Alert first time only after 1"},
|
||||||
// Alert every time, after 1
|
// Alert every time, after 1
|
||||||
{m.Monitor{ShellCommand: "false", AlertAfter: 1, AlertEvery: Ptr(1)}, []bool{true, true, true}, "Alert every time after 1"},
|
{m.Monitor{ShellCommand: "false", AlertAfter: 1, AlertEvery: new(1)}, []bool{true, true, true}, "Alert every time after 1"},
|
||||||
// Alert every other time, after 1
|
// Alert every other time, after 1
|
||||||
{m.Monitor{ShellCommand: "false", AlertAfter: 1, AlertEvery: Ptr(2)}, []bool{true, false, true, false}, "Alert every other time after 1"},
|
{m.Monitor{ShellCommand: "false", AlertAfter: 1, AlertEvery: new(2)}, []bool{true, false, true, false}, "Alert every other time after 1"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
c := c
|
|
||||||
|
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
@@ -301,7 +297,6 @@ func TestMonitorCheck(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
c := c
|
|
||||||
|
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ func TestUtilEqualSliceString(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
c := c
|
|
||||||
|
|
||||||
t.Run(fmt.Sprintf("%v %v", c.a, c.b), func(t *testing.T) {
|
t.Run(fmt.Sprintf("%v %v", c.a, c.b), func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|||||||
Reference in New Issue
Block a user