mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 11:34:26 +00:00
preserve reused code
This commit is contained in:
parent
cea0595328
commit
7692d2cb8d
36
internal/api/grpc/fields.go
Normal file
36
internal/api/grpc/fields.go
Normal file
@ -0,0 +1,36 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
)
|
||||
|
||||
// AllFieldsSet recusively checks if all values in a message
|
||||
// have a non-zero value.
|
||||
func AllFieldsSet(t testing.TB, msg protoreflect.Message, ignoreTypes ...protoreflect.FullName) {
|
||||
ignore := make(map[protoreflect.FullName]bool, len(ignoreTypes))
|
||||
for _, name := range ignoreTypes {
|
||||
ignore[name] = true
|
||||
}
|
||||
|
||||
md := msg.Descriptor()
|
||||
name := md.FullName()
|
||||
if ignore[name] {
|
||||
return
|
||||
}
|
||||
|
||||
fields := md.Fields()
|
||||
|
||||
for i := 0; i < fields.Len(); i++ {
|
||||
fd := fields.Get(i)
|
||||
if !msg.Has(fd) {
|
||||
t.Errorf("not all fields set in %q, missing %q", name, fd.Name())
|
||||
continue
|
||||
}
|
||||
|
||||
if fd.Kind() == protoreflect.MessageKind {
|
||||
AllFieldsSet(t, msg.Get(fd).Message(), ignoreTypes...)
|
||||
}
|
||||
}
|
||||
}
|
@ -141,11 +141,21 @@ func StartCommands(
|
||||
return repo, nil
|
||||
}
|
||||
|
||||
func AppendAndReduce(object interface {
|
||||
type AppendReducer interface {
|
||||
AppendEvents(...eventstore.Event)
|
||||
// TODO: Why is it allowed to return an error here?
|
||||
Reduce() error
|
||||
}, events ...eventstore.Event) error {
|
||||
}
|
||||
|
||||
func (c *Commands) pushAppendAndReduce(ctx context.Context, object AppendReducer, cmds ...eventstore.Command) error {
|
||||
events, err := c.eventstore.Push(ctx, cmds...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return AppendAndReduce(object, events...)
|
||||
}
|
||||
|
||||
func AppendAndReduce(object AppendReducer, events ...eventstore.Event) error {
|
||||
object.AppendEvents(events...)
|
||||
return object.Reduce()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user