github.com/imran-kn/cilium-fork@v1.6.9/pkg/client/client_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 client 18 19 import ( 20 "errors" 21 "fmt" 22 "testing" 23 "time" 24 25 "golang.org/x/net/context" 26 . "gopkg.in/check.v1" 27 ) 28 29 // Hook up gocheck into the "go test" runner. 30 type ClientTestSuite struct{} 31 32 var _ = Suite(&ClientTestSuite{}) 33 34 func Test(t *testing.T) { 35 TestingT(t) 36 } 37 38 func (cs *ClientTestSuite) TestHint(c *C) { 39 var err error 40 c.Assert(Hint(err), IsNil) 41 42 err = errors.New("foo bar") 43 c.Assert(Hint(err), ErrorMatches, "foo bar") 44 45 err = fmt.Errorf("ayy lmao") 46 c.Assert(Hint(err), ErrorMatches, "ayy lmao") 47 48 err = context.DeadlineExceeded 49 c.Assert(Hint(err), ErrorMatches, "Cilium API client timeout exceeded") 50 51 ctx, cancel := context.WithTimeout(context.Background(), 1*time.Millisecond) 52 defer cancel() 53 54 <-ctx.Done() 55 err = ctx.Err() 56 57 c.Assert(Hint(err), ErrorMatches, "Cilium API client timeout exceeded") 58 }