github.com/elfadel/cilium@v1.6.12/pkg/option/monitor_test.go (about)

     1  // Copyright 2018 Authors of Cilium
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // +build !privileged_tests
    16  
    17  package option
    18  
    19  import (
    20  	"strconv"
    21  
    22  	. "gopkg.in/check.v1"
    23  )
    24  
    25  func (s *OptionSuite) TestVerifyMonitorAggregationLevel(c *C) {
    26  	c.Assert(VerifyMonitorAggregationLevel("", ""), IsNil)
    27  	c.Assert(VerifyMonitorAggregationLevel("", "none"), IsNil)
    28  	c.Assert(VerifyMonitorAggregationLevel("", "disabled"), IsNil)
    29  	c.Assert(VerifyMonitorAggregationLevel("", "lowest"), IsNil)
    30  	c.Assert(VerifyMonitorAggregationLevel("", "low"), IsNil)
    31  	c.Assert(VerifyMonitorAggregationLevel("", "medium"), IsNil)
    32  	c.Assert(VerifyMonitorAggregationLevel("", "max"), IsNil)
    33  	c.Assert(VerifyMonitorAggregationLevel("", "maximum"), IsNil)
    34  	c.Assert(VerifyMonitorAggregationLevel("", "LoW"), IsNil)
    35  	c.Assert(VerifyMonitorAggregationLevel("", "disable"), NotNil)
    36  }
    37  
    38  func (s *OptionSuite) TestParseMonitorAggregationLevel(c *C) {
    39  	level, err := ParseMonitorAggregationLevel("2")
    40  	c.Assert(err, IsNil)
    41  	c.Assert(level, Equals, MonitorAggregationLevelLow)
    42  
    43  	_, err = ParseMonitorAggregationLevel(strconv.Itoa(int(MonitorAggregationLevelMax) + 1))
    44  	c.Assert(err, NotNil)
    45  
    46  	_, err = ParseMonitorAggregationLevel("-1")
    47  	c.Assert(err, NotNil)
    48  
    49  	_, err = ParseMonitorAggregationLevel("foo")
    50  	c.Assert(err, NotNil)
    51  
    52  	level, err = ParseMonitorAggregationLevel("")
    53  	c.Assert(err, IsNil)
    54  	c.Assert(level, Equals, MonitorAggregationLevelNone)
    55  
    56  	level, err = ParseMonitorAggregationLevel("none")
    57  	c.Assert(err, IsNil)
    58  	c.Assert(level, Equals, MonitorAggregationLevelNone)
    59  
    60  	level, err = ParseMonitorAggregationLevel("disabled")
    61  	c.Assert(err, IsNil)
    62  	c.Assert(level, Equals, MonitorAggregationLevelNone)
    63  
    64  	level, err = ParseMonitorAggregationLevel("lowest")
    65  	c.Assert(err, IsNil)
    66  	c.Assert(level, Equals, MonitorAggregationLevelLowest)
    67  
    68  	level, err = ParseMonitorAggregationLevel("low")
    69  	c.Assert(err, IsNil)
    70  	c.Assert(level, Equals, MonitorAggregationLevelLow)
    71  
    72  	level, err = ParseMonitorAggregationLevel("medium")
    73  	c.Assert(err, IsNil)
    74  	c.Assert(level, Equals, MonitorAggregationLevelMedium)
    75  
    76  	level, err = ParseMonitorAggregationLevel("max")
    77  	c.Assert(err, IsNil)
    78  	c.Assert(level, Equals, MonitorAggregationLevelMax)
    79  
    80  	level, err = ParseMonitorAggregationLevel("maximum")
    81  	c.Assert(err, IsNil)
    82  	c.Assert(level, Equals, MonitorAggregationLevelMax)
    83  
    84  	level, err = ParseMonitorAggregationLevel("LOW")
    85  	c.Assert(err, IsNil)
    86  	c.Assert(level, Equals, MonitorAggregationLevelLow)
    87  }