-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MM-56605: Create results file and print to file (#729)
* MM-56605: Create results file and print to file * Separate writter into its own function for later * Mofify writeToFile. Passing the file object. * implement multiWriter so I can double the writes and then send them to cosole as well as file. * Replace file object with interface. * - Remove separate function to create file - Move file creatuin and writting to the file to Comparison function * Draft unti test for PrintResults * Make test runnable by using LoadTests and Status properly. * - Solve missing use of interface in the initail code chnage - Solve whitespace mismatch * Change expected to allign with the output. This solves failing unit test. * Address most several of the code review feedback point. * Use existing file path that is already being provided to the function. * Address linter complaint about use of `Sprintf` for strings that need no formating. * Address review comments * Remove line printing an error as it was redundant. * Update another if block that redundantly prints and returns the same error. * Implement missed correction from Alejandro. If block must return the correct var when returning the error. Ensure this is not occuring on other lines I've added.
- Loading branch information
1 parent
f869c7e
commit 80e6355
Showing
2 changed files
with
110 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/mattermost/mattermost-load-test-ng/comparison" | ||
"github.com/mattermost/mattermost-load-test-ng/coordinator" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPrintResults(t *testing.T) { | ||
// Create a buffer to capture the output | ||
buf := &bytes.Buffer{} | ||
|
||
// Prepare test data | ||
results := []comparison.Result{ | ||
{ | ||
Report: "Sample Report", | ||
DashboardURL: "http://example.com/dashboard", | ||
LoadTests: [2]comparison.LoadTestResult{ | ||
{ | ||
Label: "Test1", | ||
Config: comparison.LoadTestConfig{ | ||
Type: "bounded", | ||
DBEngine: "postgres", | ||
NumUsers: 100, | ||
Duration: "10m", | ||
}, | ||
Status: coordinator.Status{ | ||
SupportedUsers: 80, | ||
NumErrors: 2, | ||
}, | ||
}, | ||
{ | ||
Label: "Test2", | ||
Config: comparison.LoadTestConfig{ | ||
Type: "bounded", | ||
DBEngine: "postgres", | ||
NumUsers: 100, | ||
Duration: "10m", | ||
}, | ||
Status: coordinator.Status{ | ||
SupportedUsers: 80, | ||
NumErrors: 2, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
// Call the function with the test data and the buffer | ||
writeResults(results, buf) | ||
|
||
// Verify the output | ||
expectedOutput := `==================================================Comparison result:Report: report_0_postgres_bounded_100.md | ||
Grafana Dashboard: http://example.com/dashboard | ||
Test1: | ||
Type: bounded | ||
DB Engine: postgres | ||
Duration: 10m | ||
Users: 100 | ||
Errors: 2 | ||
Test2: | ||
Type: bounded | ||
DB Engine: postgres | ||
Duration: 10m | ||
Users: 100 | ||
Errors: 2 | ||
================================================== | ||
` | ||
require.Equal(t, expectedOutput, buf.String()) | ||
} |