github.com/looshlee/cilium@v1.6.12/plugins/cilium-cni/chaining/api/api_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 api 18 19 import ( 20 "context" 21 "testing" 22 23 cniTypesVer "github.com/containernetworking/cni/pkg/types/current" 24 "gopkg.in/check.v1" 25 ) 26 27 func Test(t *testing.T) { 28 check.TestingT(t) 29 } 30 31 type APISuite struct{} 32 33 var _ = check.Suite(&APISuite{}) 34 35 type pluginTest struct{} 36 37 func (p *pluginTest) Add(ctx context.Context, pluginContext PluginContext) (res *cniTypesVer.Result, err error) { 38 return nil, nil 39 } 40 41 func (p *pluginTest) ImplementsAdd() bool { 42 return true 43 } 44 45 func (p *pluginTest) Delete(ctx context.Context, pluginContext PluginContext) (err error) { 46 return nil 47 } 48 49 func (p *pluginTest) ImplementsDelete() bool { 50 return true 51 } 52 53 func (a *APISuite) TestRegistration(c *check.C) { 54 err := Register("foo", &pluginTest{}) 55 c.Assert(err, check.IsNil) 56 57 err = Register("foo", &pluginTest{}) 58 c.Assert(err, check.Not(check.IsNil)) 59 60 err = Register(DefaultConfigName, &pluginTest{}) 61 c.Assert(err, check.Not(check.IsNil)) 62 }