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 fc90c15bd..b00f64b78 100644 Binary files a/timespans/test.kch and b/timespans/test.kch differ diff --git a/timespans/userbudget_test.go b/timespans/userbudget_test.go index 4721b8744..e7d1a047d 100644 --- a/timespans/userbudget_test.go +++ b/timespans/userbudget_test.go @@ -18,8 +18,9 @@ along with this program. If not, see 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) } }