Skip to content

Conversation

@ifosch
Copy link
Owner

@ifosch ifosch commented Nov 7, 2021

This improves testing code in jenkins_test.go to follow similar approaches in job_control.Job:

  • Use string to test case maps when multiple tcs (jobcontrol):
    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.

  • 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

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.
@ifosch ifosch force-pushed the improve-jenkins-tests branch from 1408f62 to 7805055 Compare November 7, 2021 21:59
os.Getenv("JENKINS_URL"),
os.Getenv("JENKINS_USER"),
os.Getenv("JENKINS_PASSWORD"),
&jobcontrol.JenkinsJobServer{},
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants