Use available balance from test case file
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing

This commit is contained in:
Jan Bader 2022-04-05 20:41:39 +00:00
parent bd99f58ab4
commit 8df7968175
2 changed files with 18 additions and 18 deletions

View File

@ -101,23 +101,24 @@ func TestMain(t *testing.T) {
name := file.Name()[0 : len(file.Name())-5] name := file.Name()[0 : len(file.Name())-5]
parts := strings.Split(name, "-") parts := strings.Split(name, "-")
year, _ := strconv.Atoi(parts[1]) year, _ := strconv.Atoi(parts[0])
month, _ := strconv.Atoi(parts[2]) month, _ := strconv.Atoi(parts[1])
first := time.Date(year, time.Month(month), 1, 0, 0, 0, 0, loc) first := time.Date(year, time.Month(month), 1, 0, 0, 0, 0, loc)
switch parts[0] {
case "categories":
t.Logf("Checking balances for %s", first.Format("2006-01")) t.Logf("Checking balances for %s", first.Format("2006-01"))
testCaseFile := filepath.Join(resultDir, file.Name()) testCaseFile := filepath.Join(resultDir, file.Name())
handler.CheckAvailableBalance(ctx, t, testCaseFile, budget, first) handler.CheckAvailableBalance(ctx, t, testCaseFile, budget, first)
} }
}
// check categories // check categories
// check accounts // check accounts
} }
type TestData struct {
AvailableBalance float64
Categories map[string]CategoryTestData
}
type CategoryTestData struct { type CategoryTestData struct {
Available float64 Available float64
Activity float64 Activity float64
@ -133,24 +134,23 @@ func (h Handler) CheckAvailableBalance(ctx context.Context, t *testing.T, testCa
return return
} }
// 2022-01 assert_equal(t, -115170.56, data.AvailableBalance.GetFloat64(), "available balance") testDataFile, err := os.Open(testCaseFile)
assertEqual(t, -110181.600, data.AvailableBalance.GetFloat64(), "available balance")
categoryTestDataFile, err := os.Open(testCaseFile)
if err != nil { if err != nil {
t.Errorf("could not load category test data: %s", err) t.Errorf("could not load category test data: %s", err)
return return
} }
var categoryTestData map[string]CategoryTestData var testData TestData
dec := json.NewDecoder(categoryTestDataFile) dec := json.NewDecoder(testDataFile)
err = dec.Decode(&categoryTestData) err = dec.Decode(&testData)
if err != nil { if err != nil {
t.Errorf("could not decode category test data: %s", err) t.Errorf("could not decode category test data: %s", err)
return return
} }
for categoryName, categoryTestData := range categoryTestData { assertEqual(t, testData.AvailableBalance, data.AvailableBalance.GetFloat64(), "available balance")
for categoryName, categoryTestData := range testData.Categories {
found := false found := false
for _, category := range data.Categories { for _, category := range data.Categories {
name := category.Group + " : " + category.Name name := category.Group + " : " + category.Name

@ -1 +1 @@
Subproject commit 58b8090d3582303bf9a89d3a322925d2b18be3a0 Subproject commit b6eda7681f92c2c635555c392660cb69bec2a1ed