Skip to content

Commit

Permalink
More helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Oct 29, 2024
1 parent ce69f0a commit 977ed8d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pachca.go
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,16 @@ func (c *Client) UploadFile(file string) (*File, error) {

// ////////////////////////////////////////////////////////////////////////////////// //

// Has returns true if properties contains property with given name
func (p Properties) Has(name string) bool {
return len(p) > 0 && p.Get(name) != nil
}

// HasAny returns true if properties contains property with one of given names
func (p Properties) HasAny(name ...string) bool {
return len(p) > 0 && p.GetAny(name...) != nil
}

// Get returns custom property with given name
func (p Properties) Get(name string) *Property {
for _, pp := range p {
Expand Down
4 changes: 4 additions & 0 deletions pachca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,14 @@ func (s *PachcaSuite) TestPropertiesHelpers(c *C) {
}

c.Assert(p.Get("test"), IsNil)
c.Assert(p.Has("test"), Equals, false)
c.Assert(p.Get("test1"), NotNil)
c.Assert(p.Has("test1"), Equals, true)

c.Assert(p.GetAny("abcd", "test100", "test"), IsNil)
c.Assert(p.HasAny("abcd", "test100", "test"), Equals, false)
c.Assert(p.GetAny("abcd", "test4", "test").Name, Equals, "test4")
c.Assert(p.HasAny("abcd", "test4", "test"), Equals, true)

c.Assert(p.Names(), DeepEquals, []string{"test1", "test2", "test3", "test4", "test5", "test6"})

Expand Down

0 comments on commit 977ed8d

Please sign in to comment.