This commit is contained in:
Vishal Saroopchand 2019-02-12 21:38:30 +00:00
Родитель 88b1631f67
Коммит ba5c69f0c8
2 изменённых файлов: 19 добавлений и 20 удалений

Просмотреть файл

@ -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())
}
}