From dd5018c99d2d70ccf479a6b1673615edb2dcc1df Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Thu, 1 Mar 2012 21:34:42 +0200 Subject: [PATCH] better test reveal mongo servialization problem --- timespans/destinations_test.go | 7 ++++--- timespans/tariff_plans_test.go | 13 +++++++++---- timespans/test.kch | Bin 6299272 -> 6300944 bytes timespans/userbudget_test.go | 20 ++++++++++---------- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/timespans/destinations_test.go b/timespans/destinations_test.go index 188e0556b..a4630ab03 100644 --- a/timespans/destinations_test.go +++ b/timespans/destinations_test.go @@ -18,6 +18,7 @@ along with this program. If not, see package timespans import ( + "reflect" "testing" ) @@ -27,7 +28,7 @@ func TestDestinationKyotoStore(t *testing.T) { nationale = &Destination{Id: "nat", Prefixes: []string{"0257", "0256", "0723"}} getter.SetDestination(nationale) result, _ := getter.GetDestination(nationale.Id) - if result.Id != nationale.Id || result.Prefixes[2] != nationale.Prefixes[2] { + if !reflect.DeepEqual(nationale, result) { t.Errorf("Expected %q was %q", nationale, result) } } @@ -41,7 +42,7 @@ func TestDestinationRedisStore(t *testing.T) { nationale = &Destination{Id: "nat", Prefixes: []string{"0257", "0256", "0723"}} getter.SetDestination(nationale) result, _ := getter.GetDestination(nationale.Id) - if result.Id != nationale.Id || result.Prefixes[2] != nationale.Prefixes[2] { + if !reflect.DeepEqual(nationale, result) { t.Errorf("Expected %q was %q", nationale, result) } } @@ -55,7 +56,7 @@ func TestDestinationMongoStore(t *testing.T) { nationale = &Destination{Id: "nat", Prefixes: []string{"0257", "0256", "0723"}} getter.SetDestination(nationale) result, _ := getter.GetDestination(nationale.Id) - if result.Id != nationale.Id || result.Prefixes[2] != nationale.Prefixes[2] { + if !reflect.DeepEqual(nationale, result) { t.Errorf("Expected %q was %q", nationale, result) } } diff --git a/timespans/tariff_plans_test.go b/timespans/tariff_plans_test.go index ca7951501..51230c469 100644 --- a/timespans/tariff_plans_test.go +++ b/timespans/tariff_plans_test.go @@ -18,6 +18,8 @@ along with this program. If not, see package timespans import ( + // "log" + "reflect" "testing" ) @@ -30,7 +32,7 @@ func TestTariffPlanKyotoStore(t *testing.T) { seara := &TariffPlan{Id: "seara_voo", SmsCredit: 100, ReceivedCallSecondsLimit: 0, MinuteBuckets: []*MinuteBucket{b1, b2}, VolumeDiscountThresholds: []*VolumeDiscount{vd}} getter.SetTariffPlan(seara) result, _ := getter.GetTariffPlan(seara.Id) - if result.SmsCredit != seara.SmsCredit || len(result.MinuteBuckets) != len(seara.MinuteBuckets) { + if !reflect.DeepEqual(seara, result) { t.Errorf("Expected %q was %q", seara, result) } } @@ -44,7 +46,7 @@ func TestTariffPlanRedisStore(t *testing.T) { seara := &TariffPlan{Id: "seara_voo", SmsCredit: 100, ReceivedCallSecondsLimit: 0, MinuteBuckets: []*MinuteBucket{b1, b2}, VolumeDiscountThresholds: []*VolumeDiscount{vd}} getter.SetTariffPlan(seara) result, _ := getter.GetTariffPlan(seara.Id) - if result.SmsCredit != seara.SmsCredit || len(result.MinuteBuckets) != len(seara.MinuteBuckets) { + if !reflect.DeepEqual(seara, result) { t.Errorf("Expected %q was %q", seara, result) } } @@ -54,10 +56,13 @@ func TestTariffPlanMongoStore(t *testing.T) { defer getter.Close() b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.01, DestinationId: "nationale"} b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"} - seara := &TariffPlan{Id: "seara_voo", SmsCredit: 100, MinuteBuckets: []*MinuteBucket{b1, b2}} + vd := &VolumeDiscount{100, 10} + seara := &TariffPlan{Id: "seara_voo", SmsCredit: 100, ReceivedCallSecondsLimit: 0, MinuteBuckets: []*MinuteBucket{b1, b2}, VolumeDiscountThresholds: []*VolumeDiscount{vd}} getter.SetTariffPlan(seara) result, _ := getter.GetTariffPlan(seara.Id) - if result.SmsCredit != seara.SmsCredit || len(result.MinuteBuckets) != len(seara.MinuteBuckets) { + if !reflect.DeepEqual(seara, result) { + t.Log(seara) + t.Log(result) t.Errorf("Expected %q was %q", seara, result) } } diff --git a/timespans/test.kch b/timespans/test.kch index fc90c15bd744926ab7d9c0727633e53b2b52437a..b00f64b782763b6cf5a8bb0531775cb2617ebfa4 100644 GIT binary patch delta 583 zcmcJ{%~C;e0EY4L=bVZdD>F4?g%pv@-kVOu8+@pXZ9#BFVk5Ev-6Q1#cDr%^sfmght Ui5A+^Rp&kZIbPb;`oHDt2Y7(*;{X5v delta 417 zcmbuxyH3JT0D$526crF1O-u|6;9UenK|xUQE-DvMKvW)~kI)Vcj6G#=?gNl?X>f6M zFusK|i>r(OJ2-sFXMO5w|6NzDxCr-UV$QHlTk&k6Na>b)11X@whY3t#3Vs9-#56*f z84cv@{FhKa499d7&k;YC;hL`Ex#IgD`(5abwFsh!VG&DM#tK%khIMQpj!h(xL<(C- zV;eijAd6k>A%{HnQ9uy~IK&Z3IK~N1afWkT;1X9T;~F=(MFmyVP{$n_xW@yUXrYZq Sbnt}d(O7#a4PW1)-R2)}?b8 package timespans import ( + // "log" + "reflect" "testing" - //"log" ) var ( @@ -58,11 +59,12 @@ func TestUserBudgetKyotoStore(t *testing.T) { defer getter.Close() b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.01, DestinationId: "nationale"} b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"} - seara := &TariffPlan{Id: "seara", SmsCredit: 100, MinuteBuckets: []*MinuteBucket{b1, b2}} - rifsBudget := &UserBudget{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, tariffPlan: seara, ResetDayOfTheMonth: 10} + rifsBudget := &UserBudget{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, ResetDayOfTheMonth: 10} getter.SetUserBudget(rifsBudget) result, _ := getter.GetUserBudget(rifsBudget.Id) - if result.SmsCredit != rifsBudget.SmsCredit || len(result.MinuteBuckets) != len(rifsBudget.MinuteBuckets) { + if !reflect.DeepEqual(rifsBudget, result) { + t.Log(rifsBudget) + t.Log(result) t.Errorf("Expected %q was %q", rifsBudget, result) } } @@ -72,11 +74,10 @@ func TestUserBudgetRedisStore(t *testing.T) { defer getter.Close() b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.01, DestinationId: "nationale"} b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"} - seara := &TariffPlan{Id: "seara", SmsCredit: 100, MinuteBuckets: []*MinuteBucket{b1, b2}} - rifsBudget := &UserBudget{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, tariffPlan: seara, ResetDayOfTheMonth: 10} + rifsBudget := &UserBudget{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, ResetDayOfTheMonth: 10} getter.SetUserBudget(rifsBudget) result, _ := getter.GetUserBudget(rifsBudget.Id) - if result.SmsCredit != rifsBudget.SmsCredit || len(result.MinuteBuckets) != len(rifsBudget.MinuteBuckets) { + if !reflect.DeepEqual(rifsBudget, result) { t.Errorf("Expected %q was %q", rifsBudget, result) } } @@ -89,11 +90,10 @@ func TestUserBudgetMongoStore(t *testing.T) { defer getter.Close() b1 := &MinuteBucket{Seconds: 10, Priority: 10, Price: 0.01, DestinationId: "nationale"} b2 := &MinuteBucket{Seconds: 100, Priority: 20, Price: 0.0, DestinationId: "retea"} - seara := &TariffPlan{Id: "seara", SmsCredit: 100, MinuteBuckets: []*MinuteBucket{b1, b2}} - rifsBudget := &UserBudget{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, tariffPlan: seara, ResetDayOfTheMonth: 10} + rifsBudget := &UserBudget{Id: "other", MinuteBuckets: []*MinuteBucket{b1, b2}, Credit: 21, ResetDayOfTheMonth: 10} getter.SetUserBudget(rifsBudget) result, _ := getter.GetUserBudget(rifsBudget.Id) - if result.SmsCredit != rifsBudget.SmsCredit || len(result.MinuteBuckets) != len(rifsBudget.MinuteBuckets) { + if !reflect.DeepEqual(rifsBudget, result) { t.Errorf("Expected %q was %q", rifsBudget, result) } }