Use available balance from test case file
This commit is contained in:
parent
bd99f58ab4
commit
8df7968175
@ -101,16 +101,12 @@ 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)
|
||||||
|
t.Logf("Checking balances for %s", first.Format("2006-01"))
|
||||||
switch parts[0] {
|
testCaseFile := filepath.Join(resultDir, file.Name())
|
||||||
case "categories":
|
handler.CheckAvailableBalance(ctx, t, testCaseFile, budget, first)
|
||||||
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 categories
|
||||||
@ -118,6 +114,11 @@ func TestMain(t *testing.T) {
|
|||||||
// 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
|
||||||
|
2
testdata
2
testdata
@ -1 +1 @@
|
|||||||
Subproject commit 58b8090d3582303bf9a89d3a322925d2b18be3a0
|
Subproject commit b6eda7681f92c2c635555c392660cb69bec2a1ed
|
Loading…
x
Reference in New Issue
Block a user