diff --git a/pkg/leakybucket/buckets_test.go b/pkg/leakybucket/buckets_test.go index 371f8eae9..1787fe818 100644 --- a/pkg/leakybucket/buckets_test.go +++ b/pkg/leakybucket/buckets_test.go @@ -22,11 +22,6 @@ type TestFile struct { Results []types.Event `yaml:"results,omitempty"` } -func testBucketStates() { - //same as a scenario, but load a bucket state first ? - -} - func TestBucket(t *testing.T) { var envSetting = os.Getenv("TEST_ONLY") @@ -261,7 +256,5 @@ POLL_AGAIN: log.Warningf("entry valid at end of loop") } } - - t.Errorf("failed test") return false } diff --git a/pkg/parser/node.go b/pkg/parser/node.go index 98623561d..1c7d2127c 100644 --- a/pkg/parser/node.go +++ b/pkg/parser/node.go @@ -399,7 +399,7 @@ func (n *Node) compile(pctx *UnixParserCtx) error { /* load grok statics */ if len(n.Grok.Statics) > 0 { //compile expr statics if present - for idx, _ := range n.Grok.Statics { + for idx := range n.Grok.Statics { if n.Grok.Statics[idx].ExpValue != "" { n.Grok.Statics[idx].RunTimeValue, err = expr.Compile(n.Grok.Statics[idx].ExpValue, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}}))) @@ -412,7 +412,7 @@ func (n *Node) compile(pctx *UnixParserCtx) error { } /* compile leafs if present */ if len(n.SuccessNodes) > 0 { - for idx, _ := range n.SuccessNodes { + for idx := range n.SuccessNodes { /*propagate debug/stats to child nodes*/ if !n.SuccessNodes[idx].Debug && n.Debug { n.SuccessNodes[idx].Debug = true @@ -432,7 +432,7 @@ func (n *Node) compile(pctx *UnixParserCtx) error { valid = true } /* load statics if present */ - for idx, _ := range n.Statics { + for idx := range n.Statics { if n.Statics[idx].ExpValue != "" { n.Statics[idx].RunTimeValue, err = expr.Compile(n.Statics[idx].ExpValue, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}}))) if err != nil { diff --git a/pkg/parser/runtime.go b/pkg/parser/runtime.go index cfe6b2981..702356120 100644 --- a/pkg/parser/runtime.go +++ b/pkg/parser/runtime.go @@ -128,11 +128,11 @@ func ProcessStatics(statics []types.ExtraField, p *types.Event, clog *logrus.Ent clog.Warningf("failed to run RunTimeValue : %v", err) continue } - switch output.(type) { + switch out := output.(type) { case string: - value = output.(string) + value = out case int: - value = strconv.Itoa(output.(int)) + value = strconv.Itoa(out) default: clog.Fatalf("unexpected return type for RunTimeValue : %T", output) return errors.New("unexpected return type for RunTimeValue") diff --git a/pkg/sqlite/stats.go b/pkg/sqlite/stats.go index 2a50767f8..c51a6086d 100644 --- a/pkg/sqlite/stats.go +++ b/pkg/sqlite/stats.go @@ -107,7 +107,7 @@ func (c *Context) GetBansAt(at time.Time) ([]map[string]string, error) { bancom["source"] = ba.MeasureSource bancom["events_count"] = "0" bancom["action"] = ba.MeasureType - bancom["until"] = fmt.Sprintf("%s", ba.Until.Sub(time.Now()).Round(time.Second)) + bancom["until"] = time.Until(ba.Until).Round(time.Second).String() bancom["reason"] = ba.Reason rets = append(rets, bancom) continue @@ -134,7 +134,7 @@ func (c *Context) GetBansAt(at time.Time) ([]map[string]string, error) { bancom["scenario"] = "?" bancom["events_count"] = "0" bancom["action"] = ba.MeasureType - bancom["until"] = fmt.Sprintf("%s", ba.Until.Sub(time.Now()).Round(time.Second)) + bancom["until"] = time.Until(ba.Until).Round(time.Second).String() bancom["reason"] = ba.Reason rets = append(rets, bancom) continue @@ -155,7 +155,7 @@ func (c *Context) GetBansAt(at time.Time) ([]map[string]string, error) { bancom["events_count"] = fmt.Sprintf("%d", evtCount) bancom["action"] = ba.MeasureType bancom["source"] = ba.MeasureSource - bancom["until"] = fmt.Sprintf("%s", ba.Until.Sub(time.Now()).Round(time.Second)) + bancom["until"] = time.Until(ba.Until).Round(time.Second).String() bancom["reason"] = so.Scenario rets = append(rets, bancom) } diff --git a/pkg/time/rate/rate_test.go b/pkg/time/rate/rate_test.go index 14b1ef32d..460078723 100644 --- a/pkg/time/rate/rate_test.go +++ b/pkg/time/rate/rate_test.go @@ -400,7 +400,7 @@ type wait struct { func runWait(t *testing.T, lim *Limiter, w wait) { start := time.Now() err := lim.WaitN(w.ctx, w.n) - delay := time.Now().Sub(start) + delay := time.Since(start) if (w.nilErr && err != nil) || (!w.nilErr && err == nil) || w.delay != dFromDuration(delay) { errString := "" if !w.nilErr {