Skip to content

Commit

Permalink
Clean some lint
Browse files Browse the repository at this point in the history
  • Loading branch information
lazyfrosch committed Mar 22, 2021
1 parent 9ed3609 commit 63a2b3f
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 26 deletions.
11 changes: 7 additions & 4 deletions benchmark.go
Expand Up @@ -25,10 +25,11 @@ type BenchmarkEvent struct {
var ActiveBenchmark *Benchmark

// NewBenchmark starts a new benchmark and records the message as event
func NewBenchmark(message string) *Benchmark {
b := &Benchmark{}
func NewBenchmark(message string) (b *Benchmark) {
b = &Benchmark{}
b.Record(message)
return b

return
}

// Initialize a Benchmark for the running program as static instance
Expand Down Expand Up @@ -60,15 +61,17 @@ func DumpBenchmarkWhen(criteria bool) {
func (b *Benchmark) Record(message string) {
t := time.Now()

var dur time.Duration

// calculate duration since last event
count := len(b.Events)
var dur time.Duration
if count > 0 {
dur = t.Sub(*b.Events[count-1].Time)
}

// read memory info
var mem runtime.MemStats

runtime.ReadMemStats(&mem)

// log the data for other use
Expand Down
1 change: 1 addition & 0 deletions benchmark_test.go
Expand Up @@ -19,6 +19,7 @@ func ExampleInitBenchmark() {
debug := true /* flags.Debug */
if debug {
InitBenchmark("Start plugin")

defer DumpBenchmarkWhen(debug /* flags.Debug */)
}

Expand Down
6 changes: 5 additions & 1 deletion config.go
@@ -1,6 +1,7 @@
package check

import (
"errors"
"fmt"
"os"
"path"
Expand Down Expand Up @@ -33,10 +34,12 @@ func NewConfig() *Config {

c.FlagSet.Usage = func() {
fmt.Printf("Usage of %s\n", c.Name)

if c.Readme != "" {
fmt.Println()
fmt.Println(c.Readme)
}

fmt.Println()
fmt.Println("Arguments:")
c.FlagSet.PrintDefaults()
Expand All @@ -61,9 +64,10 @@ func (c *Config) ParseArray(arguments []string) {

err := c.FlagSet.Parse(arguments)
if err != nil {
if err != flag.ErrHelp {
if errors.Is(err, flag.ErrHelp) {
ExitError(err)
}

BaseExit(3)
}

Expand Down
1 change: 1 addition & 0 deletions config_test.go
Expand Up @@ -14,6 +14,7 @@ func ExampleConfig() {
_ = config.FlagSet.StringP("hostname", "H", "localhost", "Hostname to check")

os.Args = []string{"check_example", "--help"}

config.ParseArguments()

log.Info("test")
Expand Down
7 changes: 2 additions & 5 deletions convert/bytesize_test.go
Expand Up @@ -23,10 +23,7 @@ func ExampleParseBytes() {
}

func TestParseBytes(t *testing.T) {
var b *Bytesize
var err error

err, b = ParseBytes(uint64(1))
err, b := ParseBytes(uint64(1))
assert.NoError(t, err)
assert.Equal(t, float64(1), b.Data)
assert.Equal(t, "B", b.Unit)
Expand Down Expand Up @@ -61,7 +58,7 @@ func TestParseBytes(t *testing.T) {
assert.Equal(t, -1.123, b.Data)
assert.Equal(t, "MB", b.Unit)

err, b = ParseBytes("foobar")
err, _ = ParseBytes("foobar")
assert.Error(t, err)
}

Expand Down
18 changes: 2 additions & 16 deletions go.sum
Expand Up @@ -2,36 +2,22 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc=
github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.0 h1:jlIyCplCJFULU/01vCkhKuTyc3OorI3bJFuw6obfgho=
github.com/stretchr/testify v1.6.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4 changes: 4 additions & 0 deletions result/overall.go
Expand Up @@ -66,15 +66,19 @@ func (o *Overall) GetSummary() string {
if o.Criticals > 0 {
o.Summary += fmt.Sprintf("critical=%d ", o.Criticals)
}

if o.Unknowns > 0 {
o.Summary += fmt.Sprintf("unknown=%d ", o.Unknowns)
}

if o.Warnings > 0 {
o.Summary += fmt.Sprintf("warning=%d ", o.Warnings)
}

if o.OKs > 0 {
o.Summary += fmt.Sprintf("ok=%d ", o.OKs)
}

if o.Summary == "" {
o.Summary = "No status information"
} else {
Expand Down
1 change: 1 addition & 0 deletions status.go
Expand Up @@ -22,5 +22,6 @@ func StatusText(status int) string {
return "CRITICAL"
case Unknown:
}

return "UNKNOWN"
}
4 changes: 4 additions & 0 deletions testhelper/for_main.go
Expand Up @@ -13,9 +13,11 @@ import (
func RunMainTest(f func(), args ...string) string {
base := []string{"check_with_go_test"}
origArgs := os.Args

os.Args = append(base, args...)
stdout := CaptureStdout(f)
os.Args = origArgs

return stdout
}

Expand Down Expand Up @@ -50,9 +52,11 @@ func CaptureStdout(f func()) string {
f()

w.Close()

os.Stdout = old

var buf bytes.Buffer
_, _ = io.Copy(&buf, r)

return buf.String()
}
1 change: 1 addition & 0 deletions timeout.go
Expand Up @@ -20,6 +20,7 @@ func HandleTimeout(timeout int) {
// signal handling has already been set up
return
}

signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)

Expand Down

0 comments on commit 63a2b3f

Please sign in to comment.