Rename option; cleanup
This commit is contained in:
Родитель
88b1631f67
Коммит
ba5c69f0c8
18
namespace.go
18
namespace.go
|
@ -54,10 +54,10 @@ type (
|
|||
// Namespace provides a simplified facade over the AMQP implementation of Azure Service Bus and is the entry point
|
||||
// for using Queues, Topics and Subscriptions
|
||||
Namespace struct {
|
||||
Name string
|
||||
TokenProvider auth.TokenProvider
|
||||
Environment azure.Environment
|
||||
telemetryValue string
|
||||
Name string
|
||||
TokenProvider auth.TokenProvider
|
||||
Environment azure.Environment
|
||||
userAgent string
|
||||
}
|
||||
|
||||
// NamespaceOption provides structure for configuring a new Service Bus namespace
|
||||
|
@ -83,10 +83,10 @@ func NamespaceWithConnectionString(connStr string) NamespaceOption {
|
|||
}
|
||||
}
|
||||
|
||||
// NamespaceWithTelemetryValue appends value to the root user-agent value.
|
||||
func NamespaceWithTelemetryValue(value string) NamespaceOption {
|
||||
// NamespaceWithUserAgent appends to the root user-agent value.
|
||||
func NamespaceWithUserAgent(userAgent string) NamespaceOption {
|
||||
return func(ns *Namespace) error {
|
||||
ns.telemetryValue = value
|
||||
ns.userAgent = userAgent
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -142,8 +142,8 @@ func (ns *Namespace) getEntityAudience(entityPath string) string {
|
|||
|
||||
func (ns *Namespace) getUserAgent() string {
|
||||
userAgent := rootUserAgent
|
||||
if ns.telemetryValue != "" {
|
||||
userAgent = fmt.Sprintf("%s/%s", userAgent, ns.telemetryValue)
|
||||
if ns.userAgent != "" {
|
||||
userAgent = fmt.Sprintf("%s/%s", userAgent, ns.userAgent)
|
||||
}
|
||||
return userAgent
|
||||
}
|
||||
|
|
|
@ -28,19 +28,18 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNamespaceWithTelemetryOption(t *testing.T) {
|
||||
telemetryValue := "customer-telemetry-value"
|
||||
nsTelemetryOption := NamespaceWithTelemetryValue(telemetryValue)
|
||||
ns, err := NewNamespace(nsTelemetryOption)
|
||||
func TestNamespaceWithUserAgentOption(t *testing.T) {
|
||||
userAgent := "custom-user-agent"
|
||||
nsUserAgentOption := NamespaceWithUserAgent(userAgent)
|
||||
ns, err := NewNamespace(nsUserAgentOption)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, fmt.Sprintf("%s/%s", rootUserAgent, telemetryValue), ns.getUserAgent())
|
||||
assert.Equal(t, fmt.Sprintf("%s/%s", rootUserAgent, userAgent), ns.getUserAgent())
|
||||
}
|
||||
|
||||
func TestNamespaceWithoutTelemetryOption(t *testing.T) {
|
||||
telemetryValue := ""
|
||||
nsTelemetryOption := NamespaceWithTelemetryValue(telemetryValue)
|
||||
ns, err := NewNamespace(nsTelemetryOption)
|
||||
func TestNamespaceWithoutUserAgentOption(t *testing.T) {
|
||||
userAgent := ""
|
||||
nsUserAgentOption := NamespaceWithUserAgent(userAgent)
|
||||
ns, err := NewNamespace(nsUserAgentOption)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, rootUserAgent, ns.getUserAgent())
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче