Revision b9098e6b25f97b4af51ebec3c24f5cf6ad48551f authored by Gilberto Bertin on 29 February 2024, 07:36:40 UTC, committed by Martynas Pumputis on 29 February 2024, 15:47:00 UTC
currently some functions in policy.h reference POLICY_MAP, assuming it's
always defined. This prevents including this header in a context where
the POLICY_MAP is not defined.

To overcome this, remove all the POLICY_MAP references from these
functions and always pass the map explicitly in the caller.

No functional changes are introduced.

Signed-off-by: Gilberto Bertin <jibi@cilium.io>
1 parent d7dba5e
Raw File
monitor_test.go
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium

package option

import (
	"strconv"

	. "github.com/cilium/checkmate"
)

func (s *OptionSuite) TestVerifyMonitorAggregationLevel(c *C) {
	c.Assert(VerifyMonitorAggregationLevel("", ""), IsNil)
	c.Assert(VerifyMonitorAggregationLevel("", "none"), IsNil)
	c.Assert(VerifyMonitorAggregationLevel("", "disabled"), IsNil)
	c.Assert(VerifyMonitorAggregationLevel("", "lowest"), IsNil)
	c.Assert(VerifyMonitorAggregationLevel("", "low"), IsNil)
	c.Assert(VerifyMonitorAggregationLevel("", "medium"), IsNil)
	c.Assert(VerifyMonitorAggregationLevel("", "max"), IsNil)
	c.Assert(VerifyMonitorAggregationLevel("", "maximum"), IsNil)
	c.Assert(VerifyMonitorAggregationLevel("", "LoW"), IsNil)
	c.Assert(VerifyMonitorAggregationLevel("", "disable"), NotNil)
}

func (s *OptionSuite) TestParseMonitorAggregationLevel(c *C) {
	level, err := ParseMonitorAggregationLevel("2")
	c.Assert(err, IsNil)
	c.Assert(level, Equals, MonitorAggregationLevelLow)

	_, err = ParseMonitorAggregationLevel(strconv.Itoa(int(MonitorAggregationLevelMax) + 1))
	c.Assert(err, NotNil)

	_, err = ParseMonitorAggregationLevel("-1")
	c.Assert(err, NotNil)

	_, err = ParseMonitorAggregationLevel("foo")
	c.Assert(err, NotNil)

	level, err = ParseMonitorAggregationLevel("")
	c.Assert(err, IsNil)
	c.Assert(level, Equals, MonitorAggregationLevelNone)

	level, err = ParseMonitorAggregationLevel("none")
	c.Assert(err, IsNil)
	c.Assert(level, Equals, MonitorAggregationLevelNone)

	level, err = ParseMonitorAggregationLevel("disabled")
	c.Assert(err, IsNil)
	c.Assert(level, Equals, MonitorAggregationLevelNone)

	level, err = ParseMonitorAggregationLevel("lowest")
	c.Assert(err, IsNil)
	c.Assert(level, Equals, MonitorAggregationLevelLowest)

	level, err = ParseMonitorAggregationLevel("low")
	c.Assert(err, IsNil)
	c.Assert(level, Equals, MonitorAggregationLevelLow)

	level, err = ParseMonitorAggregationLevel("medium")
	c.Assert(err, IsNil)
	c.Assert(level, Equals, MonitorAggregationLevelMedium)

	level, err = ParseMonitorAggregationLevel("max")
	c.Assert(err, IsNil)
	c.Assert(level, Equals, MonitorAggregationLevelMax)

	level, err = ParseMonitorAggregationLevel("maximum")
	c.Assert(err, IsNil)
	c.Assert(level, Equals, MonitorAggregationLevelMax)

	level, err = ParseMonitorAggregationLevel("LOW")
	c.Assert(err, IsNil)
	c.Assert(level, Equals, MonitorAggregationLevelLow)
}
back to top