Repository navigation
Add unit tests - #21
Merged
Merged
Conversation
The project had no tests. Add JUnit 6 and tests for the code that decides what runs on deploy hosts: - DeployerFacadeTest: who may deploy (the env's request service user, adm-admin, nobody anonymous), unknown app envs, and the semver check that keeps shell syntax out of the version appended to the deploy command. - SSHFacadeTest: runs deploy commands against an in-process MINA SSH server with scripted commands: the version is appended, a nonzero exit keeps its exit code and output, a prompt gets no input, a hanging command times out, and a failed login is recorded. - FunctionsTest: the duration text on the log page. For SSHFacadeTest, SSHFacade gets two seams: createClient(), which the test overrides to use its own key and to ignore ~/.ssh, and a non-final commandTimeout, which the test shortens. CI's ./gradlew build runs the tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
slominskir
approved these changes
Oct 1, 2026
slominskir
left a comment
Member
There was a problem hiding this comment.
Certainly better than no tests...
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The project had no tests. This adds JUnit 6 (
org.junit:junit-bom:6.1.3) and 32 tests for the code that decides what runs on deploy hosts. CI's./gradlew build(jeffersonlab/java-workflowsunit-ci.yaml) runs them.Tests
DeployerFacadeTest(23): who may deploy (the env's request service user andadm-admincan; another user, an empty name, andanonymouscan't), an unknown app env, and the semver check. The version is appended to a command run in a shell, so the rejected versions include1.0.0; rm -rf /,1.0.0|id,1.0.0-$(id), a trailing newline, and a trailing space. Collaborators are small subclass fakes, plus aProxyforSessionContext, so no mocking library is needed.SSHFacadeTest(5): runsasyncExecuteRemoteCommandagainst an in-process MINA SSH server whose commands are scripted in Java, so there's no shell or container to set up. It checks that the version is appended, a nonzero exit keeps its exit code and output (Record the deploy command's real exit code and output #17), a prompt gets no input (Give deploy commands empty input #20), a hanging command times out (Time out deploy commands after 10 minutes #19), and a failed login is recorded. The client uses a generated key and ignores~/.ssh(keys,config,known_hosts), so running the tests never touches the developer's SSH files.FunctionsTest(4): the duration text on/log.Changes to production code
SSHFacadegets two package-private seams for its test:createClient()returnsSshClient.setUpDefaultClient(), as before; the test overrides it.commandTimeoutis no longerfinal, so the test can shorten it.The README's Develop section says how to run the tests.
Checks
./gradlew spotlessCheck buildpasses in thegradle:9-jdk21container; the tests take about 3 seconds.promptGetsNoInput,versionIsAppendedToCommand, andotherUserCannotDeployfailed.Found while writing the tests
A deploy request without a
verparameter throws aNullPointerExceptionfromPattern.matcher(null)inDeployerFacade.validateSemver, rather than the "Version string must be semver formatted" message. I left it out of this PR, so there's no test for a null version.🤖 Generated with Claude Code