Use subtests
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

This commit is contained in:
Jan Bader 2022-04-05 20:52:37 +00:00
parent 49d96be1e3
commit 150a7d562b

View File

@ -87,12 +87,16 @@ func TestMain(t *testing.T) {
loc := time.Now().Location()
AssertCategoriesAndAvailableEqual(t, loc, handler, ctx, budget)
AssertCategoriesAndAvailableEqual(ctx, t, loc, handler, budget)
// check accounts
}
func AssertCategoriesAndAvailableEqual(t *testing.T, loc *time.Location, handler *Handler, ctx context.Context, budget *postgres.Budget) {
func AssertCategoriesAndAvailableEqual(ctx context.Context, t *testing.T, loc *time.Location, handler *Handler, budget *postgres.Budget) {
t.Helper()
t.Run("Categories and available balance", func(t *testing.T) {
t.Parallel()
resultDir := "../testdata/production-export/results"
files, err := os.ReadDir(resultDir)
if err != nil {
@ -110,10 +114,10 @@ func AssertCategoriesAndAvailableEqual(t *testing.T, loc *time.Location, handler
year, _ := strconv.Atoi(parts[0])
month, _ := strconv.Atoi(parts[1])
first := time.Date(year, time.Month(month), 1, 0, 0, 0, 0, loc)
t.Logf("Checking balances for %s", first.Format("2006-01"))
testCaseFile := filepath.Join(resultDir, file.Name())
handler.CheckAvailableBalance(ctx, t, testCaseFile, budget, first)
}
})
}
type TestData struct {
@ -130,6 +134,8 @@ type CategoryTestData struct {
func (h Handler) CheckAvailableBalance(ctx context.Context, t *testing.T, testCaseFile string, budget *postgres.Budget, first time.Time) {
t.Helper()
t.Run(first.Format("2006-01"), func(t *testing.T) {
t.Parallel()
data, err := h.prepareBudgeting(ctx, *budget, first)
if err != nil {
t.Errorf("prepare budgeting: %s", err)
@ -169,6 +175,7 @@ func (h Handler) CheckAvailableBalance(ctx context.Context, t *testing.T, testCa
t.Errorf("category " + categoryName + " was not found in result")
}
}
})
}
func assertEqual(t *testing.T, expected, actual float64, message string) {