Пример #1
0
func TestIsRoot(t *testing.T) {
	in := "#"
	r1, err := New(in)
	assert.NoError(t, err)
	assert.True(t, r1.IsRoot())

	in = "#/ok"
	r1 = MustCreateRef(in)
	assert.False(t, r1.IsRoot())

	assert.Panics(t, assert.PanicTestFunc(func() {
		MustCreateRef("%2")
	}))
}
Пример #2
0
func TestWrapOnewayHandlerInvalid(t *testing.T) {
	tests := []struct {
		Name string
		Func interface{}
	}{
		{"empty", func() {}},
		{"not-a-function", 0},
		{
			"wrong-args-in",
			func(context.Context, yarpc.ReqMeta) error {
				return nil
			},
		},
		{
			"wrong-ctx",
			func(string, yarpc.ReqMeta, *struct{}) error {
				return nil
			},
		},
		{
			"wrong-req-meta",
			func(context.Context, yarpc.CallReqMeta, *struct{}) error {
				return nil
			},
		},
		{
			"wrong-req-body",
			func(context.Context, string, int) error {
				return nil
			},
		},
		{
			"wrong-response",
			func(context.Context, yarpc.ReqMeta, map[string]interface{}) (*struct{}, yarpc.ResMeta, error) {
				return nil, nil, nil
			},
		},
		{
			"wrong-response-val",
			func(context.Context, yarpc.ReqMeta, map[string]interface{}) int {
				return 0
			},
		},
		{
			"non-pointer-req",
			func(context.Context, yarpc.ReqMeta, struct{}) error {
				return nil
			},
		},
		{
			"non-string-key",
			func(context.Context, yarpc.ReqMeta, map[int32]interface{}) error {
				return nil
			},
		},
	}

	for _, tt := range tests {
		assert.Panics(t, assert.PanicTestFunc(func() {
			wrapOnewayHandler(tt.Name, tt.Func)
		}))
	}
}