Skip to content

Commit

Permalink
Add helper Property.IsSet
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Oct 31, 2024
1 parent bbf2aad commit 8d2c488
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pachca.go
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,11 @@ func (p Properties) Names() []string {
return result
}

// IsSet returns true if property has a value
func (p *Property) IsSet() bool {
return p != nil && p.Value != ""
}

// IsText returns true if property has text type
func (p *Property) IsText() bool {
return p != nil && p.Type == PROP_TYPE_TEXT
Expand Down
4 changes: 4 additions & 0 deletions pachca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ func (s *PachcaSuite) TestPropertiesHelpers(c *C) {
c.Assert(p.Find("test1"), NotNil)
c.Assert(p.Has("test1"), Equals, true)

c.Assert(p.Get(6).IsSet(), Equals, false)
c.Assert(p.Get(10).IsSet(), Equals, false)
c.Assert(p.Get(1).IsSet(), Equals, true)

c.Assert(p.FindAny("abcd", "test100", "test"), IsNil)
c.Assert(p.HasAny("abcd", "test100", "test"), Equals, false)
c.Assert(p.FindAny("abcd", "test4", "test").Name, Equals, "test4")
Expand Down

0 comments on commit 8d2c488

Please sign in to comment.