Skip to content

Commit

Permalink
Add func Unsubscribe.Filters
Browse files Browse the repository at this point in the history
  • Loading branch information
gregoryv committed Oct 22, 2023
1 parent 4b1d1ed commit 4ddc97f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to http://semver.org/spec/v2.0.0.html.

## [unreleased]

- Add func Unsubscribe.Filters
- Update dependencies

## [0.27.0] 2023-01-15
Expand Down
7 changes: 7 additions & 0 deletions unsubscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ func (p *Unsubscribe) PacketID() uint16 { return uint16(p.packetID) }
func (p *Unsubscribe) AddFilter(filter string) {
p.filters = append(p.filters, wstring(filter))
}
func (p *Unsubscribe) Filters() []string {
res := make([]string, len(p.filters))
for i, v := range p.filters {
res[i] = string(v)
}
return res
}

func (p *Unsubscribe) WriteTo(w io.Writer) (int64, error) {
b := make([]byte, p.width())
Expand Down
3 changes: 3 additions & 0 deletions unsubscribe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func TestUnsubscribe(t *testing.T) {
s.AddFilter("a/b/c")
s.AddFilter("d/e")

if v := s.Filters(); len(v) != 2 {
t.Error("expect 2 filters, got", v)
}
if v := s.String(); !strings.Contains(v, "SUBSCRIBE --1-") {
t.Errorf("%q expect to contain %q", v, "SUBSCRIBE --1-")
}
Expand Down

0 comments on commit 4ddc97f

Please sign in to comment.