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) } }
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()) } }
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") } }
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()) } }
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") } }
func TestDefaultMux(t *testing.T) { // test if default mux implements mux var m perm.Mux = perm.NewMux() _ = m }