Skip to content

Commit

Permalink
Add Package.ResourceNames
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfireman committed Nov 13, 2017
1 parent 581f997 commit 0d27d01
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ func (p *Package) GetResource(name string) *resource.Resource {
return nil
}

// ResourceNames return a slice containing the name of the resources.
func (p *Package) ResourceNames() []string {
s := make([]string, len(p.resources))
for i, r := range p.resources {
s[i] = r.Name
}
return s
}

// AddResource adds a new resource to the package, updating its descriptor accordingly.
func (p *Package) AddResource(d map[string]interface{}) error {
if p.resFactory == nil {
Expand Down
8 changes: 8 additions & 0 deletions pkg/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ func TestPackage_RemoveResource(t *testing.T) {
})
}

func TestPackage_ResourceNames(t *testing.T) {
is := is.New(t)
p := Package{resFactory: validResource}
is.True(p.AddResource(map[string]interface{}{"name": "res1"}) == nil)
is.True(p.AddResource(map[string]interface{}{"name": "res2"}) == nil)
is.Equal(p.ResourceNames(), []string{"res1", "res2"})
}

func TestFromDescriptor(t *testing.T) {
t.Run("ValidationErrors", func(t *testing.T) {
is := is.New(t)
Expand Down

0 comments on commit 0d27d01

Please sign in to comment.