@@ -5,6 +5,7 @@ package useragent
55
66import (
77 "fmt"
8+ "os"
89 "sync"
910 "testing"
1011
@@ -284,3 +285,46 @@ func TestListen(t *testing.T) {
284285 ua .SetContainerInsightsFlag ()
285286 wg .Wait ()
286287}
288+
289+ func TestSetComponents_WithDualStackEndpoint (t * testing.T ) {
290+ // Save original env var
291+ originalEnv := os .Getenv (envconfig .AWS_USE_DUALSTACK_ENDPOINT )
292+ defer func () {
293+ if originalEnv == "" {
294+ os .Unsetenv (envconfig .AWS_USE_DUALSTACK_ENDPOINT )
295+ } else {
296+ os .Setenv (envconfig .AWS_USE_DUALSTACK_ENDPOINT , originalEnv )
297+ }
298+ }()
299+
300+ t .Run ("ipv6_feature_added_when_dualstack_enabled" , func (t * testing.T ) {
301+ os .Setenv (envconfig .AWS_USE_DUALSTACK_ENDPOINT , "true" )
302+ ua := newUserAgent ()
303+ ua .SetComponents (& otelcol.Config {}, & telegraf.Config {})
304+
305+ assert .Contains (t , ua .feature , "ipv6" )
306+ assert .Contains (t , ua .featureStr .Load (), "ipv6" )
307+ header := ua .Header (true )
308+ assert .Contains (t , header , "feature:(ipv6)" )
309+ })
310+
311+ t .Run ("ipv6_feature_not_added_when_dualstack_disabled" , func (t * testing.T ) {
312+ os .Setenv (envconfig .AWS_USE_DUALSTACK_ENDPOINT , "false" )
313+ ua := newUserAgent ()
314+ ua .SetComponents (& otelcol.Config {}, & telegraf.Config {})
315+
316+ assert .NotContains (t , ua .feature , "ipv6" )
317+ header := ua .Header (true )
318+ assert .NotContains (t , header , "ipv6" )
319+ })
320+
321+ t .Run ("ipv6_feature_not_added_when_dualstack_not_set" , func (t * testing.T ) {
322+ os .Unsetenv (envconfig .AWS_USE_DUALSTACK_ENDPOINT )
323+ ua := newUserAgent ()
324+ ua .SetComponents (& otelcol.Config {}, & telegraf.Config {})
325+
326+ assert .NotContains (t , ua .feature , "ipv6" )
327+ header := ua .Header (true )
328+ assert .NotContains (t , header , "ipv6" )
329+ })
330+ }
0 commit comments