-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ISSUE #989] consumer and producer client add unit support (WithUnitN…
…ame) [ISSUE #989] consumer and producer client add unit support (WithUnitName)
- Loading branch information
1 parent
7ae788d
commit 7f3ffe2
Showing
6 changed files
with
213 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package consumer | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func getFieldString(obj interface{}, field string) string { | ||
v := reflect.Indirect(reflect.ValueOf(obj)) | ||
return v.FieldByNameFunc(func(n string) bool { | ||
return n == field | ||
}).String() | ||
} | ||
|
||
func TestWithUnitName(t *testing.T) { | ||
opt := defaultPullConsumerOptions() | ||
unitName := "unsh" | ||
WithUnitName(unitName)(&opt) | ||
if opt.UnitName != unitName { | ||
t.Errorf("consumer option WithUnitName. want:%s, got=%s", unitName, opt.UnitName) | ||
} | ||
} | ||
|
||
func TestWithNameServerDomain(t *testing.T) { | ||
opt := defaultPullConsumerOptions() | ||
nameServerAddr := "http://127.0.0.1:8080/nameserver/addr" | ||
WithNameServerDomain(nameServerAddr)(&opt) | ||
domainStr := getFieldString(opt.Resolver, "domain") | ||
if domainStr != nameServerAddr { | ||
t.Errorf("consumer option WithUnitName. want:%s, got=%s", nameServerAddr, domainStr) | ||
} | ||
} | ||
|
||
func TestWithNameServerDomainAndUnitName(t *testing.T) { | ||
nameServerAddr := "http://127.0.0.1:8080/nameserver/addr" | ||
unitName := "unsh" | ||
suffix := fmt.Sprintf("-%s?nofix=1", unitName) | ||
|
||
// test with two different orders | ||
t.Run("WithNameServerDomain & WithUnitName", func(t *testing.T) { | ||
opt := defaultPullConsumerOptions() | ||
WithNameServerDomain(nameServerAddr)(&opt) | ||
WithUnitName(unitName)(&opt) | ||
|
||
domainStr := getFieldString(opt.Resolver, "domain") | ||
if !strings.Contains(domainStr, nameServerAddr) || !strings.Contains(domainStr, suffix) { | ||
t.Errorf("consumer option should contains %s and %s", nameServerAddr, suffix) | ||
} | ||
}) | ||
|
||
t.Run("WithUnitName & WithNameServerDomain", func(t *testing.T) { | ||
opt := defaultPullConsumerOptions() | ||
WithNameServerDomain(nameServerAddr)(&opt) | ||
WithUnitName(unitName)(&opt) | ||
|
||
domainStr := getFieldString(opt.Resolver, "domain") | ||
if !strings.Contains(domainStr, nameServerAddr) || !strings.Contains(domainStr, suffix) { | ||
t.Errorf("consumer option should contains %s and %s", nameServerAddr, suffix) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package producer | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func getFieldString(obj interface{}, field string) string { | ||
v := reflect.Indirect(reflect.ValueOf(obj)) | ||
return v.FieldByNameFunc(func(n string) bool { | ||
return n == field | ||
}).String() | ||
} | ||
|
||
func TestWithUnitName(t *testing.T) { | ||
opt := defaultProducerOptions() | ||
unitName := "unsh" | ||
WithUnitName(unitName)(&opt) | ||
if opt.UnitName != unitName { | ||
t.Errorf("consumer option WithUnitName. want:%s, got=%s", unitName, opt.UnitName) | ||
} | ||
} | ||
|
||
func TestWithNameServerDomain(t *testing.T) { | ||
opt := defaultProducerOptions() | ||
nameServerAddr := "http://127.0.0.1:8080/nameserver/addr" | ||
WithNameServerDomain(nameServerAddr)(&opt) | ||
domainStr := getFieldString(opt.Resolver, "domain") | ||
if domainStr != nameServerAddr { | ||
t.Errorf("consumer option WithUnitName. want:%s, got=%s", nameServerAddr, domainStr) | ||
} | ||
} | ||
|
||
func TestWithNameServerDomainAndUnitName(t *testing.T) { | ||
nameServerAddr := "http://127.0.0.1:8080/nameserver/addr" | ||
unitName := "unsh" | ||
suffix := fmt.Sprintf("-%s?nofix=1", unitName) | ||
|
||
// test with two different orders | ||
t.Run("WithNameServerDomain & WithUnitName", func(t *testing.T) { | ||
opt := defaultProducerOptions() | ||
WithNameServerDomain(nameServerAddr)(&opt) | ||
WithUnitName(unitName)(&opt) | ||
|
||
domainStr := getFieldString(opt.Resolver, "domain") | ||
if !strings.Contains(domainStr, nameServerAddr) || !strings.Contains(domainStr, suffix) { | ||
t.Errorf("consumer option should contains %s and %s", nameServerAddr, suffix) | ||
} | ||
}) | ||
|
||
t.Run("WithUnitName & WithNameServerDomain", func(t *testing.T) { | ||
opt := defaultProducerOptions() | ||
WithNameServerDomain(nameServerAddr)(&opt) | ||
WithUnitName(unitName)(&opt) | ||
|
||
domainStr := getFieldString(opt.Resolver, "domain") | ||
if !strings.Contains(domainStr, nameServerAddr) || !strings.Contains(domainStr, suffix) { | ||
t.Errorf("consumer option should contains %s and %s", nameServerAddr, suffix) | ||
} | ||
}) | ||
} |