Exemplo n.º 1
0
// test duration
func TestDuration(t *testing.T) {
	if e.DbName == "" {
		t.Skip("Skipping DB Tests, $DB_NAME not set")
	}
	line := []byte(`{"uuid": "8F0DA3E6A6F311E1B35A12313B05658A",
	"device": 1,
	"app": 22,
	"timestampMs": 100000,
	"timestamp": 100,
	"scope": "catalog",
	"action": "pageview",
	"duration": -100,
	"year": 2012,
	"quarter": 1}`)
	var err error
	in, err := UnmarshalEvent(line)
	if err != nil {
		t.Log(err)
		t.Errorf("unmarhsaling.. this should not fail")
	}
	out, errs := CleanCatalogPageview(connection, in)
	for _, err := range errs {
		if err == nil {
			t.Log(err)
			t.Errorf("this should fail")
		}
	}
	value, err := event.GetValue("Duration", out)
	if value != float64(0) {
		t.Errorf("got %+v", out)
		t.Errorf("got %v wanted %v", value, 0)
	}
}
Exemplo n.º 2
0
//TestTImestamp check if the timestamp are properly hanlded
func TestTimestamp(t *testing.T) {
	if e.DbName == "" {
		t.Skip("Skipping DB Tests, $DB_NAME not set")
	}
	line := []byte(`{"uuid": "8F0DA3E6A6F311E1B35A12313B05658A",
	"device": 1,
	"app": 22,
	"timestampMs": 100000,
	"timestamp": 100,
	"scope": "offer",
	"action": "view",
	"date_year": "2012-01-01T00:00:00+00:00",
	"date_quarter": "2012-01-01T00:00:00+00:00",
	"date_month": "2012-03-01T00:00:00+00:00",
	"date_week": "2012-02-27T00:00:00+00:00",
	"date_day": "2012-03-01T00:00:00+00:00",
	"date_hour": "2012-03-01T00:00:00+00:00",
	"date_minute": "2012-03-01T00:00:00+00:00",
	"date_second": "2012-03-01T00:00:15+00:00",
	"year": 2012,
	"quarter": 1}`)
	var err error
	in, err := UnmarshalEvent(line)
	if err != nil {
		t.Log(err)
		t.Errorf("unmarhsaling.. this should not fail")
	}
	out := clean.Offer_View{}
	out, errs := CleanOfferView(connection, in)
	for _, err := range errs {
		if err != nil {
			t.Log(err)
			t.Errorf("this should not fail")
		}
	}
	value, err := event.GetValue("Timestamp", out)
	if value != 100.0 {
		t.Log(err)
		t.Errorf("got %+v", out)
		t.Errorf("got %s wanted %s", value, 100.0)
	}
	line = []byte(`{"uuid": "8F0DA3E6A6F311E1B35A12313B05658A",
	"device": 1,
	"app": 22,
	"timestamp": 100,
	"scope": "offer",
	"action": "view",
	"date_year": "2012-01-01T00:00:00+00:00",
	"date_quarter": "2012-01-01T00:00:00+00:00",
	"date_month": "2012-03-01T00:00:00+00:00",
	"date_week": "2012-02-27T00:00:00+00:00",
	"date_day": "2012-03-01T00:00:00+00:00",
	"date_hour": "2012-03-01T00:00:00+00:00",
	"date_minute": "2012-03-01T00:00:00+00:00",
	"date_second": "2012-03-01T00:00:15+00:00",
	"year": 2012,
	"quarter": 1}`)

	in, err = UnmarshalEvent(line)
	if err != nil {
		t.Log(err)
		t.Errorf("unmarhsaling.. this should not fail")
	}
	out, errs = CleanOfferView(connection, in)
	for _, err := range errs {
		if err != nil {
			t.Log(err)
			t.Errorf("this should not fail")
		}
	}
	value, err = event.GetValue("Timestamp", out)
	if value != 100.0 {
		t.Log(err)
		t.Errorf("got %+v", out)
		t.Errorf("got %s wanted %s", value, 100.0)
	}

}