示例#1
0
文件: mux_test.go 项目: gourd/kit
func TestMuxNotFound(t *testing.T) {
	m := perm.NewMux()
	err := m.Allow(nil, "access something")
	if err != perm.HandlerNotFound {
		t.Errorf("Error is not of expected type. Expecting perm.HandlerNotFound by get %#v", err)
	}
}
示例#2
0
文件: context_test.go 项目: gourd/kit
func TestGetMux(t *testing.T) {
	ep := testEndpoint()
	_, err := ep(perm.WithMux(nil, perm.NewMux()), nil)
	if err != nil {
		t.Errorf("test error: %#v", err.Error())
	}
}
示例#3
0
文件: mux_test.go 项目: gourd/kit
func TestMuxFoundMux(t *testing.T) {

	// child mux
	m1 := perm.NewMux()
	m1.HandleFunc("access something", func(ctx context.Context, perm string, info ...interface{}) error {
		return nil
	})

	// parent mux
	m2 := perm.NewMux()
	m2.Handle("access something", m1)

	// test parent mux
	if err := m2.Allow(nil, "access something"); err != nil {
		t.Errorf("Unexpected error. Failed to obtain handler for permission")
	}
}
示例#4
0
文件: context_test.go 项目: gourd/kit
func TestMiddleware(t *testing.T) {
	ep := testEndpoint()
	var mw endpoint.Middleware = perm.UseMux(perm.NewMux())
	_, err := mw(ep)(nil, nil)
	if err != nil {
		t.Errorf("test error: %#v", err.Error())
	}
}
示例#5
0
文件: mux_test.go 项目: gourd/kit
func TestMuxFoundFunc(t *testing.T) {
	m := perm.NewMux()
	m.HandleFunc("access something", func(ctx context.Context, perm string, info ...interface{}) error {
		return nil
	})
	if err := m.Allow(nil, "access something"); err != nil {
		t.Errorf("Unexpected error. Failed to obtain handler for permission")
	}
}
示例#6
0
文件: mux_test.go 项目: gourd/kit
func TestDefaultMux(t *testing.T) {
	// test if default mux implements mux
	var m perm.Mux = perm.NewMux()
	_ = m
}