extra tests for topup after load

This commit is contained in:
Radu Ioan Fericean
2014-03-01 00:02:56 +02:00
parent b557e2a5a4
commit e6b02b84c0
3 changed files with 47 additions and 0 deletions

View File

@@ -978,6 +978,29 @@ func TestTopupAction(t *testing.T) {
}
}
func TestTopupActionLoaded(t *testing.T) {
initialUb, _ := accountingStorage.GetAccount("*out:vdf:minitsboy")
a := &Action{
ActionType: "*topup",
BalanceType: CREDIT,
Direction: OUTBOUND,
Balance: &Balance{Value: 25, DestinationId: "RET", Weight: 20},
}
at := &ActionTiming{
AccountIds: []string{"*out:vdf:minitsboy"},
actions: Actions{a},
}
at.Execute()
afterUb, _ := accountingStorage.GetAccount("*out:vdf:minitsboy")
initialValue := initialUb.BalanceMap[CREDIT+OUTBOUND].GetTotalValue()
afterValue := afterUb.BalanceMap[CREDIT+OUTBOUND].GetTotalValue()
if initialValue != 100 || afterValue != 125 {
t.Error("Bad topup before and after: ", initialValue, afterValue)
}
}
/********************************** Benchmarks ********************************/
func BenchmarkUUID(b *testing.B) {

View File

@@ -62,11 +62,25 @@ func populateDB() {
&Balance{Value: 100, DestinationId: "RET", Weight: 20},
}},
}
// this is added to test if csv load tests account will not overwrite balances
minitsboy := &Account{
Id: "*out:vdf:minitsboy",
BalanceMap: map[string]BalanceChain{
MINUTES + OUTBOUND: BalanceChain{
&Balance{Value: 20, DestinationId: "NAT", Weight: 10, RateSubject: "rif"},
&Balance{Value: 100, DestinationId: "RET", Weight: 20},
},
CREDIT + OUTBOUND: BalanceChain{
&Balance{Value: 100, Weight: 10},
},
},
}
if accountingStorage != nil {
accountingStorage.SetActions("TEST_ACTIONS", ats)
accountingStorage.SetActions("TEST_ACTIONS_ORDER", ats1)
accountingStorage.SetAccount(broker)
accountingStorage.SetAccount(minu)
accountingStorage.SetAccount(minitsboy)
} else {
log.Fatal("Could not connect to db!")
}

View File

@@ -754,6 +754,16 @@ func TestLoadAccountActions(t *testing.T) {
if !reflect.DeepEqual(aa, expected) {
t.Error("Error loading account action: ", aa)
}
// test that it does not overwrite balances
existing, err := accountingStorage.GetAccount(aa.Id)
if err != nil || len(existing.BalanceMap) != 2 {
t.Errorf("The account was not set before load: %+v", existing)
}
accountingStorage.SetAccount(aa)
existing, err = accountingStorage.GetAccount(aa.Id)
if err != nil || len(existing.BalanceMap) != 2 {
t.Errorf("The set account altered the balances: %+v", existing)
}
}
func TestLoadAliases(t *testing.T) {