Read tests from file
This commit is contained in:
parent
5f6bea4ee2
commit
f0993fd9c3
@ -87,18 +87,15 @@ type CategoryTestData struct {
|
||||
func (h Handler) CheckAvailableBalance(ctx context.Context, t *testing.T, budget *postgres.Budget) {
|
||||
t.Helper()
|
||||
loc := time.Now().Location()
|
||||
first := time.Date(2022, 1, 1, 0, 0, 0, 0, loc)
|
||||
firstOfNextMonth := time.Date(2022, 2, 1, 0, 0, 0, 0, loc)
|
||||
first := time.Date(2021, 12, 1, 0, 0, 0, 0, loc)
|
||||
firstOfNextMonth := time.Date(2022, 1, 1, 0, 0, 0, 0, loc)
|
||||
data, err := h.prepareBudgeting(ctx, *budget, firstOfNextMonth, first)
|
||||
if err != nil {
|
||||
t.Errorf("prepare budgeting: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if data.AvailableBalance.GetFloat64() != -115170.56 {
|
||||
t.Errorf("available balance is wrong")
|
||||
return
|
||||
}
|
||||
assert_equal(t, -115170.56, data.AvailableBalance.GetFloat64(), "available balance")
|
||||
|
||||
categoryTestDataFile, err := os.Open("../testdata/production-export/results/categories-2021-12.json")
|
||||
if err != nil {
|
||||
@ -114,17 +111,26 @@ func (h Handler) CheckAvailableBalance(ctx context.Context, t *testing.T, budget
|
||||
return
|
||||
}
|
||||
|
||||
for categoryName, categoryTestData := range categoryTestData {
|
||||
for _, category := range data.Categories {
|
||||
if category.Name == "Young & Home" {
|
||||
if category.Available.GetFloat64() != 67.55 {
|
||||
t.Errorf("available for category Young & Home is wrong")
|
||||
}
|
||||
if category.Activity.GetFloat64() != -107.78 {
|
||||
t.Errorf("available for category Young & Home is wrong")
|
||||
}
|
||||
name := category.Group + " : " + category.Name
|
||||
|
||||
if name == categoryName {
|
||||
assert_equal(t, categoryTestData.Available, category.Available.GetFloat64(), "available for "+categoryName)
|
||||
assert_equal(t, categoryTestData.Activity, category.Activity.GetFloat64(), "activity for "+categoryName)
|
||||
assert_equal(t, categoryTestData.Assigned, category.Assigned.GetFloat64(), "assigned for "+categoryName)
|
||||
}
|
||||
fmt.Printf("%s: %f %f\n", category.Name, category.Activity.GetFloat64(), category.Available.GetFloat64())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func assert_equal(t *testing.T, expected, actual float64, message string) {
|
||||
if expected == actual {
|
||||
return
|
||||
}
|
||||
|
||||
t.Errorf("%s: expected %f, got %f", message, expected, actual)
|
||||
}
|
||||
|
||||
func (h Handler) DoYNABImport(ctx context.Context, t *testing.T, budget *postgres.Budget) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user