github.com/newrelic/go-agent@v3.26.0+incompatible/internal/browser_test.go (about)

     1  // Copyright 2020 New Relic Corporation. All rights reserved.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package internal
     5  
     6  import (
     7  	"testing"
     8  )
     9  
    10  func TestBrowserAttributesNil(t *testing.T) {
    11  	expected := `{"u":{},"a":{}}`
    12  	actual := string(BrowserAttributes(nil))
    13  	if expected != actual {
    14  		t.Errorf("unexpected browser attributes: expected %s; got %s", expected, actual)
    15  	}
    16  }
    17  
    18  func TestBrowserAttributes(t *testing.T) {
    19  	a := NewAttributes(CreateAttributeConfig(sampleAttributeConfigInput, true))
    20  	AddUserAttribute(a, "user", "thing", destBrowser)
    21  	AddUserAttribute(a, "not", "shown", destError)
    22  	a.Agent.Add(AttributeHostDisplayName, "host", nil)
    23  
    24  	expected := `{"u":{"user":"thing"},"a":{}}`
    25  	actual := string(BrowserAttributes(a))
    26  	if expected != actual {
    27  		t.Errorf("unexpected browser attributes: expected %s; got %s", expected, actual)
    28  	}
    29  }