Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group builder #59

Merged
merged 10 commits into from
Jan 14, 2019
15 changes: 15 additions & 0 deletions pkg/builder/group/group_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
// Builder for creating a GroupDTO
type AbstractBuilder struct {
groupId string
displayName string
entityTypePtr *proto.EntityDTO_EntityType
memberList []string
matching *Matching
Expand Down Expand Up @@ -66,6 +67,10 @@ func (groupBuilder *AbstractBuilder) Build() (*proto.GroupDTO, error) {
Info: groupId,
}

if groupBuilder.displayName != "" {
groupDTO.DisplayName = &groupBuilder.displayName
}

err := groupBuilder.setupEntityType(groupDTO)
if err != nil {
groupBuilder.ec.Collect(err)
Expand Down Expand Up @@ -93,6 +98,16 @@ func (groupBuilder *AbstractBuilder) Build() (*proto.GroupDTO, error) {
return groupDTO, nil
}

func (groupBuilder *AbstractBuilder) WithDisplayName(displayName string) *AbstractBuilder {
if displayName == "" {
return groupBuilder
}
// Setup entity type
groupBuilder.displayName = displayName

return groupBuilder
}

// Set the entity type for the members of the group.
// All the entities in a group belong to the same entity type.
func (groupBuilder *AbstractBuilder) OfType(eType proto.EntityDTO_EntityType) *AbstractBuilder {
Expand Down
19 changes: 19 additions & 0 deletions pkg/builder/group/group_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,22 @@ func TestGroupBuilderSetConsistentResize(t *testing.T) {

fmt.Printf("%++v\n", groupDTO)
}

func TestGroupBuilderDisplayName(t *testing.T) {
id := "group1"
eType := proto.EntityDTO_CONTAINER

groupBuilder := StaticGroup(id).
OfType(eType).
WithEntities([]string{"abc", "xyz"})

groupDTO, _ := groupBuilder.Build()

assert.Equal(t, id, groupDTO.GetDisplayName())

displayName := "Test Group"
groupBuilder.WithDisplayName(displayName)
groupDTO, _ = groupBuilder.Build()

assert.Equal(t, displayName, groupDTO.GetDisplayName())
}