more linting fixes

This commit is contained in:
Thibault bui Koechlin 2020-05-20 11:26:21 +02:00
parent fe68914628
commit e6cad40ac4
5 changed files with 10 additions and 17 deletions

View file

@ -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
}

View file

@ -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 {

View file

@ -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")

View file

@ -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)
}

View file

@ -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 := "<nil>"
if !w.nilErr {