Use available balance from test case file
This commit is contained in:
		| @@ -101,23 +101,24 @@ 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) | ||||||
|  |  | ||||||
| 		switch parts[0] { |  | ||||||
| 		case "categories": |  | ||||||
| 		t.Logf("Checking balances for %s", first.Format("2006-01")) | 		t.Logf("Checking balances for %s", first.Format("2006-01")) | ||||||
| 		testCaseFile := filepath.Join(resultDir, file.Name()) | 		testCaseFile := filepath.Join(resultDir, file.Name()) | ||||||
| 		handler.CheckAvailableBalance(ctx, t, testCaseFile, budget, first) | 		handler.CheckAvailableBalance(ctx, t, testCaseFile, budget, first) | ||||||
| 	} | 	} | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	// check categories | 	// check categories | ||||||
|  |  | ||||||
| 	// 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
									
									
									
									
									
								
							 Submodule testdata updated: 58b8090d35...b6eda7681f
									
								
							
		Reference in New Issue
	
	Block a user