github.phpd.cn/cilium/cilium@v1.6.12/pkg/aws/eni/metrics/mock/mock_test.go (about) 1 // Copyright 2019 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 mock 18 19 import ( 20 "testing" 21 "time" 22 23 "gopkg.in/check.v1" 24 ) 25 26 func Test(t *testing.T) { 27 check.TestingT(t) 28 } 29 30 type MockSuite struct{} 31 32 var _ = check.Suite(&MockSuite{}) 33 34 func (e *MockSuite) TestMock(c *check.C) { 35 api := NewMockMetrics() 36 api.IncENIAllocationAttempt("foo", "s-1") 37 c.Assert(api.ENIAllocationAttempts("foo", "s-1"), check.Equals, int64(1)) 38 api.AddIPAllocation("s-1", 10) 39 api.AddIPAllocation("s-1", 20) 40 c.Assert(api.IPAllocations("s-1"), check.Equals, int64(30)) 41 api.SetAllocatedIPs("used", 200) 42 c.Assert(api.AllocatedIPs("used"), check.Equals, 200) 43 api.SetAvailableENIs(10) 44 c.Assert(api.AvailableENIs(), check.Equals, 10) 45 api.SetNodes("at-capacity", 5) 46 c.Assert(api.Nodes("at-capacity"), check.Equals, 5) 47 api.ObserveEC2APICall("DescribeNetworkInterfaces", "success", 2.0) 48 c.Assert(api.EC2APICall("DescribeNetworkInterfaces", "success"), check.Equals, 2.0) 49 api.ObserveEC2RateLimit("DescribeNetworkInterfaces", time.Second) 50 api.ObserveEC2RateLimit("DescribeNetworkInterfaces", time.Second) 51 c.Assert(api.EC2RateLimit("DescribeNetworkInterfaces"), check.Equals, 2*time.Second) 52 api.IncResyncCount() 53 c.Assert(api.ResyncCount(), check.Equals, int64(1)) 54 }