diff --git a/server/main_test.go b/server/main_test.go index 5302976..4e828f3 100644 --- a/server/main_test.go +++ b/server/main_test.go @@ -101,16 +101,12 @@ 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) - } + 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 @@ -118,6 +114,11 @@ func TestMain(t *testing.T) { // 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 diff --git a/testdata b/testdata index 58b8090..b6eda76 160000 --- a/testdata +++ b/testdata @@ -1 +1 @@ -Subproject commit 58b8090d3582303bf9a89d3a322925d2b18be3a0 +Subproject commit b6eda7681f92c2c635555c392660cb69bec2a1ed