@ -74,6 +74,8 @@ func TestIntegrationDeviceService_tag(t *testing.T) {
req [ ] tagReq
expectedAnonCount int64
expectedAuthedCount int64
expectedAnonUICount int64
expectedAuthedUICount int64
expectedDevice * Device
} {
{
@ -112,11 +114,33 @@ func TestIntegrationDeviceService_tag(t *testing.T) {
IP : "10.30.30.1" ,
UserAgent : "test" } ,
} ,
{
name : "should tag device ID once" ,
req : [ ] tagReq { { httpReq : & http . Request {
Header : http . Header {
"User-Agent" : [ ] string { "test" } ,
"X-Forwarded-For" : [ ] string { "10.30.30.1" } ,
http . CanonicalHeaderKey ( deviceIDHeader ) : [ ] string { "32mdo31deeqwes" } ,
} ,
} ,
kind : anonymous . AnonDevice ,
} ,
} ,
expectedAnonUICount : 1 ,
expectedAuthedUICount : 0 ,
expectedAnonCount : 1 ,
expectedAuthedCount : 0 ,
expectedDevice : & Device {
Kind : anonymous . AnonDevice ,
IP : "10.30.30.1" ,
UserAgent : "test" } ,
} ,
{
name : "repeat request should not tag" ,
req : [ ] tagReq { { httpReq : & http . Request {
Header : http . Header {
"User-Agent" : [ ] string { "test" } ,
http . CanonicalHeaderKey ( deviceIDHeader ) : [ ] string { "32mdo31deeqwes" } ,
"X-Forwarded-For" : [ ] string { "10.30.30.1" } ,
} ,
} ,
@ -124,6 +148,7 @@ func TestIntegrationDeviceService_tag(t *testing.T) {
} , { httpReq : & http . Request {
Header : http . Header {
"User-Agent" : [ ] string { "test" } ,
http . CanonicalHeaderKey ( deviceIDHeader ) : [ ] string { "32mdo31deeqwes" } ,
"X-Forwarded-For" : [ ] string { "10.30.30.1" } ,
} ,
} ,
@ -131,12 +156,14 @@ func TestIntegrationDeviceService_tag(t *testing.T) {
} ,
} ,
expectedAnonCount : 1 ,
expectedAnonUICount : 1 ,
expectedAuthedCount : 0 ,
} , {
name : "authed request should untag anon" ,
req : [ ] tagReq { { httpReq : & http . Request {
Header : http . Header {
"User-Agent" : [ ] string { "test" } ,
http . CanonicalHeaderKey ( deviceIDHeader ) : [ ] string { "32mdo31deeqwes" } ,
"X-Forwarded-For" : [ ] string { "10.30.30.1" } ,
} ,
} ,
@ -144,6 +171,7 @@ func TestIntegrationDeviceService_tag(t *testing.T) {
} , { httpReq : & http . Request {
Header : http . Header {
"User-Agent" : [ ] string { "test" } ,
http . CanonicalHeaderKey ( deviceIDHeader ) : [ ] string { "32mdo31deeqwes" } ,
"X-Forwarded-For" : [ ] string { "10.30.30.1" } ,
} ,
} ,
@ -152,11 +180,13 @@ func TestIntegrationDeviceService_tag(t *testing.T) {
} ,
expectedAnonCount : 0 ,
expectedAuthedCount : 1 ,
expectedAuthedUICount : 1 ,
} , {
name : "anon request should untag authed" ,
req : [ ] tagReq { { httpReq : & http . Request {
Header : http . Header {
"User-Agent" : [ ] string { "test" } ,
http . CanonicalHeaderKey ( deviceIDHeader ) : [ ] string { "32mdo31deeqwes" } ,
"X-Forwarded-For" : [ ] string { "10.30.30.1" } ,
} ,
} ,
@ -164,6 +194,7 @@ func TestIntegrationDeviceService_tag(t *testing.T) {
} , { httpReq : & http . Request {
Header : http . Header {
"User-Agent" : [ ] string { "test" } ,
http . CanonicalHeaderKey ( deviceIDHeader ) : [ ] string { "32mdo31deeqwes" } ,
"X-Forwarded-For" : [ ] string { "10.30.30.1" } ,
} ,
} ,
@ -171,14 +202,16 @@ func TestIntegrationDeviceService_tag(t *testing.T) {
} ,
} ,
expectedAnonCount : 1 ,
expectedAnonUICount : 1 ,
expectedAuthedCount : 0 ,
} ,
{
name : "tag 4 different requests" ,
name : "tag 4 different requests - 2 are UI " ,
req : [ ] tagReq { { httpReq : & http . Request {
Header : http . Header {
"User-Agent" : [ ] string { "test" } ,
"X-Forwarded-For" : [ ] string { "10.30.30.1" } ,
http . CanonicalHeaderKey ( "User-Agent" ) : [ ] string { "test" } ,
http . CanonicalHeaderKey ( "X-Forwarded-For" ) : [ ] string { "10.30.30.1" } ,
http . CanonicalHeaderKey ( deviceIDHeader ) : [ ] string { "a" } ,
} ,
} ,
kind : anonymous . AnonDevice ,
@ -193,6 +226,7 @@ func TestIntegrationDeviceService_tag(t *testing.T) {
Header : http . Header {
"User-Agent" : [ ] string { "test" } ,
"X-Forwarded-For" : [ ] string { "10.30.30.3" } ,
http . CanonicalHeaderKey ( deviceIDHeader ) : [ ] string { "c" } ,
} ,
} ,
kind : anonymous . AuthedDevice ,
@ -207,6 +241,8 @@ func TestIntegrationDeviceService_tag(t *testing.T) {
} ,
expectedAnonCount : 2 ,
expectedAuthedCount : 2 ,
expectedAnonUICount : 1 ,
expectedAuthedUICount : 1 ,
} ,
}
@ -226,6 +262,8 @@ func TestIntegrationDeviceService_tag(t *testing.T) {
assert . Equal ( t , tc . expectedAnonCount , stats [ "stats.anonymous.session.count" ] . ( int64 ) )
assert . Equal ( t , tc . expectedAuthedCount , stats [ "stats.users.device.count" ] . ( int64 ) )
assert . Equal ( t , tc . expectedAnonUICount , stats [ "stats.anonymous.device.ui.count" ] . ( int64 ) )
assert . Equal ( t , tc . expectedAuthedUICount , stats [ "stats.users.device.ui.count" ] . ( int64 ) )
if tc . expectedDevice != nil {
key , err := tc . expectedDevice . Key ( )