2023-06-01 12:05:20 +00:00
|
|
|
package dockerversion
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2023-06-01 12:09:50 +00:00
|
|
|
"github.com/docker/docker/pkg/useragent"
|
2023-06-01 12:05:20 +00:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDockerUserAgent(t *testing.T) {
|
|
|
|
t.Run("daemon user-agent", func(t *testing.T) {
|
|
|
|
ua := DockerUserAgent(context.TODO())
|
|
|
|
expected := getDaemonUserAgent()
|
|
|
|
assert.Check(t, is.Equal(ua, expected))
|
|
|
|
})
|
|
|
|
|
2023-06-01 12:09:50 +00:00
|
|
|
t.Run("daemon user-agent custom metadata", func(t *testing.T) {
|
|
|
|
ua := DockerUserAgent(context.TODO(), useragent.VersionInfo{Name: "hello", Version: "world"}, useragent.VersionInfo{Name: "foo", Version: "bar"})
|
|
|
|
expected := getDaemonUserAgent() + ` hello/world foo/bar`
|
|
|
|
assert.Check(t, is.Equal(ua, expected))
|
|
|
|
})
|
|
|
|
|
2023-06-01 12:05:20 +00:00
|
|
|
t.Run("daemon user-agent with upstream", func(t *testing.T) {
|
|
|
|
ctx := context.WithValue(context.TODO(), UAStringKey{}, "Magic-Client/1.2.3 (linux)")
|
|
|
|
ua := DockerUserAgent(ctx)
|
|
|
|
expected := getDaemonUserAgent() + ` UpstreamClient(Magic-Client/1.2.3 \(linux\))`
|
|
|
|
assert.Check(t, is.Equal(ua, expected))
|
|
|
|
})
|
2023-06-01 12:09:50 +00:00
|
|
|
|
|
|
|
t.Run("daemon user-agent with upstream and custom metadata", func(t *testing.T) {
|
|
|
|
ctx := context.WithValue(context.TODO(), UAStringKey{}, "Magic-Client/1.2.3 (linux)")
|
|
|
|
ua := DockerUserAgent(ctx, useragent.VersionInfo{Name: "hello", Version: "world"}, useragent.VersionInfo{Name: "foo", Version: "bar"})
|
|
|
|
expected := getDaemonUserAgent() + ` hello/world foo/bar UpstreamClient(Magic-Client/1.2.3 \(linux\))`
|
|
|
|
assert.Check(t, is.Equal(ua, expected))
|
|
|
|
})
|
2023-06-01 12:05:20 +00:00
|
|
|
}
|