github.com/imran-kn/cilium-fork@v1.6.9/pkg/debug/subsystem_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 debug
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/cilium/cilium/pkg/checker"
    23  
    24  	. "gopkg.in/check.v1"
    25  )
    26  
    27  // Hook up gocheck into the "go test" runner.
    28  func Test(t *testing.T) {
    29  	TestingT(t)
    30  }
    31  
    32  type DebugTestSuite struct{}
    33  
    34  var _ = Suite(&DebugTestSuite{})
    35  
    36  type debugObj struct{}
    37  
    38  func (d *debugObj) DebugStatus() string {
    39  	return "test3"
    40  }
    41  
    42  func (s *DebugTestSuite) TestSubsystem(c *C) {
    43  	sf := newStatusFunctions()
    44  	c.Assert(sf.collectStatus(), checker.DeepEquals, StatusMap{})
    45  
    46  	sf = newStatusFunctions()
    47  	sf.register("foo", func() string { return "test1" })
    48  	c.Assert(sf.collectStatus(), checker.DeepEquals, StatusMap{
    49  		"foo": "test1",
    50  	})
    51  
    52  	sf.register("bar", func() string { return "test2" })
    53  	c.Assert(sf.collectStatus(), checker.DeepEquals, StatusMap{
    54  		"foo": "test1",
    55  		"bar": "test2",
    56  	})
    57  
    58  	sf.register("bar", func() string { return "test2" })
    59  	c.Assert(sf.collectStatus(), checker.DeepEquals, StatusMap{
    60  		"foo": "test1",
    61  		"bar": "test2",
    62  	})
    63  
    64  	sf.registerStatusObject("baz", &debugObj{})
    65  	c.Assert(sf.collectStatus(), checker.DeepEquals, StatusMap{
    66  		"foo": "test1",
    67  		"bar": "test2",
    68  		"baz": "test3",
    69  	})
    70  }