-
Notifications
You must be signed in to change notification settings - Fork 2
Improve Jenkins tests #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
This makes all the remaining tests in `jobcontrol` package to use the same structure for test cases (mapping strings to test cases). Now all these tests are similar to the tests for `jobcontrol.Job`, and the ones in the `slack` package.
After these changes, the tests for Jenkins are easier to read, understand, and write. The expected jobs available are now also global to all the Jenkins tests, reducing the cognitive load.
This removes some cognitive load in Jenkins tests.
Most of the lists compared in these tests are slices of strings, or something very similar. This provides a couple of helpers to convert the types to string lists and another one to compare string lists easily.
This function provides the most complex and common fixtures to tests, making the tests code easy to write and read.
1408f62 to
7805055
Compare
| os.Getenv("JENKINS_URL"), | ||
| os.Getenv("JENKINS_USER"), | ||
| os.Getenv("JENKINS_PASSWORD"), | ||
| &jobcontrol.JenkinsJobServer{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be fine to construct the Jenkins object manually when testing instead of using the NewJenkins function. I'm not sure if adding this to the public signature of jobcontrol.NewJenkins is an improvement. It brings the question of control over JenkinsJobServer, and if the user needs any control there.
This improves testing code in
jenkins_test.goto follow similar approaches injob_control.Job:Use string to test case maps when multiple tcs (jobcontrol):
This makes all the remaining tests in
jobcontrolpackage to usethe same structure for test cases (mapping strings to test
cases). Now all these tests are similar to the tests for
jobcontrol.Job, and the ones in theslackpackage.Use NewJenkins in tests after injecting IJobServer: After these
changes, the tests for Jenkins are easier to read, understand, and
write. The expected jobs available are now also global to all the
Jenkins tests, reducing the cognitive load.
Replace loadTC with simple variables: This removes some
cognitive load in Jenkins tests.
Simplify string comparisons in tests
Use t.Run in TestDescribe: This function provides the most
complex and common fixtures to tests, making the tests code easy to
write and read.
Simplify tests by grouping common stuff in a setup func
Reorganize the Jenkins tests code
Add better detail to test error message
Adjust some lines' length to improve readability