Skip to content

Commit

Permalink
Group builder (#59)
Browse files Browse the repository at this point in the history
* Group and policy builders - add display name
  • Loading branch information
pallavidn authored Jan 14, 2019
1 parent 8f47c27 commit aed6fd0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
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())
}

0 comments on commit aed6fd0

Please sign in to comment.