Skip to content
This repository has been archived by the owner on Dec 14, 2020. It is now read-only.

Commit

Permalink
Making SessionID nillable when creating a new Link.
Browse files Browse the repository at this point in the history
Fixes #134
  • Loading branch information
marstr authored and vcabbage committed Oct 18, 2018
1 parent 271d628 commit 8df994b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
18 changes: 13 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1506,19 +1506,19 @@ func LinkReceiverSettle(mode ReceiverSettleMode) LinkOption {

// LinkSessionFilter sets a session filter (com.microsoft:session-filter) on the link source.
// This is used in Azure Service Bus to filter messages by session ID on a receiving link.
func LinkSessionFilter(sessionID string) LinkOption {
func LinkSessionFilter(sessionID *string) LinkOption {
// <descriptor name="com.microsoft:session-filter" code="00000013:7000000C"/>
return linkSourceFilter("com.microsoft:session-filter", uint64(0x00000137000000C), sessionID)
}

// LinkSelectorFilter sets a selector filter (apache.org:selector-filter:string) on the link source.
func LinkSelectorFilter(filter string) LinkOption {
// <descriptor name="apache.org:selector-filter:string" code="0x0000468C:0x00000004"/>
return linkSourceFilter("apache.org:selector-filter:string", uint64(0x0000468C00000004), filter)
return linkSourceFilter("apache.org:selector-filter:string", uint64(0x0000468C00000004), &filter)
}

// linkSourceFilter sets a filter on the link source.
func linkSourceFilter(name string, code uint64, value string) LinkOption {
func linkSourceFilter(name string, code uint64, value *string) LinkOption {
nameSym := symbol(name)
return func(l *link) error {
if l.source == nil {
Expand All @@ -1527,10 +1527,18 @@ func linkSourceFilter(name string, code uint64, value string) LinkOption {
if l.source.Filter == nil {
l.source.Filter = make(map[symbol]*describedType)
}
l.source.Filter[nameSym] = &describedType{

describedValue := &describedType{
descriptor: code,
value: value,
}

if value == nil {
describedValue.value = nil
} else {
describedValue.value = *value
}

l.source.Filter[nameSym] = describedValue
return nil
}
}
Expand Down
21 changes: 19 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
)

func TestLinkOptions(t *testing.T) {
sessionID := "123"

tests := []struct {
label string
opts []LinkOption
Expand All @@ -24,7 +26,7 @@ func TestLinkOptions(t *testing.T) {
LinkProperty("x-opt-test2", "test2"),
LinkProperty("x-opt-test1", "test3"),
LinkPropertyInt64("x-opt-test4", 1),
LinkSessionFilter("123"),
LinkSessionFilter(&sessionID),
},

wantSource: &source{
Expand All @@ -35,7 +37,7 @@ func TestLinkOptions(t *testing.T) {
},
"com.microsoft:session-filter" : {
descriptor: binary.BigEndian.Uint64([]byte{0x00, 0x00, 0x00, 0x13, 0x70, 0x00, 0x00, 0x0C}),
value: "123",
value: sessionID,
},
},
},
Expand All @@ -45,6 +47,21 @@ func TestLinkOptions(t *testing.T) {
"x-opt-test4": int64(1),
},
},
{
label: "more-link-filters",
opts: []LinkOption{
LinkSessionFilter(nil),
},

wantSource: &source{
Filter: map[symbol]*describedType{
"com.microsoft:session-filter" : {
descriptor: binary.BigEndian.Uint64([]byte{0x00, 0x00, 0x00, 0x13, 0x70, 0x00, 0x00, 0x0C}),
value: nil,
},
},
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 8df994b

Please sign in to comment.