Use available balance from test case file
This commit is contained in:
parent
bd99f58ab4
commit
8df7968175
@ -101,23 +101,24 @@ func TestMain(t *testing.T) {
|
||||
|
||||
name := file.Name()[0 : len(file.Name())-5]
|
||||
parts := strings.Split(name, "-")
|
||||
year, _ := strconv.Atoi(parts[1])
|
||||
month, _ := strconv.Atoi(parts[2])
|
||||
year, _ := strconv.Atoi(parts[0])
|
||||
month, _ := strconv.Atoi(parts[1])
|
||||
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"))
|
||||
testCaseFile := filepath.Join(resultDir, file.Name())
|
||||
handler.CheckAvailableBalance(ctx, t, testCaseFile, budget, first)
|
||||
}
|
||||
}
|
||||
|
||||
// check categories
|
||||
|
||||
// check accounts
|
||||
}
|
||||
|
||||
type TestData struct {
|
||||
AvailableBalance float64
|
||||
Categories map[string]CategoryTestData
|
||||
}
|
||||
|
||||
type CategoryTestData struct {
|
||||
Available float64
|
||||
Activity float64
|
||||
@ -133,24 +134,23 @@ func (h Handler) CheckAvailableBalance(ctx context.Context, t *testing.T, testCa
|
||||
return
|
||||
}
|
||||
|
||||
// 2022-01 assert_equal(t, -115170.56, data.AvailableBalance.GetFloat64(), "available balance")
|
||||
assertEqual(t, -110181.600, data.AvailableBalance.GetFloat64(), "available balance")
|
||||
|
||||
categoryTestDataFile, err := os.Open(testCaseFile)
|
||||
testDataFile, err := os.Open(testCaseFile)
|
||||
if err != nil {
|
||||
t.Errorf("could not load category test data: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
var categoryTestData map[string]CategoryTestData
|
||||
dec := json.NewDecoder(categoryTestDataFile)
|
||||
err = dec.Decode(&categoryTestData)
|
||||
var testData TestData
|
||||
dec := json.NewDecoder(testDataFile)
|
||||
err = dec.Decode(&testData)
|
||||
if err != nil {
|
||||
t.Errorf("could not decode category test data: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
for categoryName, categoryTestData := range categoryTestData {
|
||||
assertEqual(t, testData.AvailableBalance, data.AvailableBalance.GetFloat64(), "available balance")
|
||||
|
||||
for categoryName, categoryTestData := range testData.Categories {
|
||||
found := false
|
||||
for _, category := range data.Categories {
|
||||
name := category.Group + " : " + category.Name
|
||||
|
2
testdata
2
testdata
@ -1 +1 @@
|
||||
Subproject commit 58b8090d3582303bf9a89d3a322925d2b18be3a0
|
||||
Subproject commit b6eda7681f92c2c635555c392660cb69bec2a1ed
|
Loading…
x
Reference in New Issue
Block a user