Beispiel #1
0
// ParseCIDR parses value of the CIDR from string
func ParseCIDR(v string) (*CIDR, error) {
	ip, ipnet, err := net.ParseCIDR(v)
	if err != nil {
		return nil, trace.BadParameter("failed to parse CIDR(%v): %v", v, err.Error())
	}
	return &CIDR{val: v, ip: ip, ipnet: *ipnet}, nil
}
Beispiel #2
0
// TestTraces makes sure we pass traces via metadata and can decode it back
func (s *TrailSuite) TestTraces(c *C) {
	err := trace.BadParameter("param")
	meta := metadata.New(nil)
	SetDebugInfo(err, meta)
	err2 := FromGRPC(ToGRPC(err), meta)
	c.Assert(line(trace.DebugReport(err)), Matches, ".*trail_test.go.*")
	c.Assert(line(trace.DebugReport(err2)), Matches, ".*trail_test.go.*")
}
Beispiel #3
0
// TestConversion makes sure we convert all trace supported errors
// to and back from GRPC codes
func (s *TrailSuite) TestConversion(c *C) {
	type TestCase struct {
		Error     error
		Message   string
		Predicate func(error) bool
	}
	testCases := []TestCase{
		{
			Error:     trace.AccessDenied("access denied"),
			Predicate: trace.IsAccessDenied,
		},
		{
			Error:     trace.ConnectionProblem(nil, "problem"),
			Predicate: trace.IsConnectionProblem,
		},
		{
			Error:     trace.NotFound("not found"),
			Predicate: trace.IsNotFound,
		},
		{
			Error:     trace.BadParameter("bad parameter"),
			Predicate: trace.IsBadParameter,
		},
		{
			Error:     trace.CompareFailed("compare failed"),
			Predicate: trace.IsCompareFailed,
		},
		{
			Error:     trace.AccessDenied("denied"),
			Predicate: trace.IsAccessDenied,
		},
		{
			Error:     trace.LimitExceeded("exceeded"),
			Predicate: trace.IsLimitExceeded,
		},
	}
	for i, tc := range testCases {
		comment := Commentf("test case #v", i+1)
		grpcError := ToGRPC(tc.Error)
		c.Assert(grpc.ErrorDesc(grpcError), Equals, tc.Error.Error(), comment)
		out := FromGRPC(grpcError)
		c.Assert(tc.Predicate(out), Equals, true, comment)
	}
}