Skip to content

Add unit tests - #21

Merged
slominskir merged 1 commit into
mainfrom
unit-tests
Oct 1, 2026
Merged

slominskir merged 1 commit into
mainfrom
unit-tests

Conversation

@slominskir-coding-agent

Copy link
Copy Markdown
Contributor

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-workflows unit-ci.yaml) runs them.

Tests

  • DeployerFacadeTest (23): who may deploy (the env's request service user and adm-admin can; another user, an empty name, and anonymous can't), an unknown app env, and the semver check. The version is appended to a command run in a shell, so the rejected versions include 1.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 a Proxy for SessionContext, so no mocking library is needed.
  • SSHFacadeTest (5): runs asyncExecuteRemoteCommand against 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

SSHFacade gets two package-private seams for its test:

  • createClient() returns SshClient.setUpDefaultClient(), as before; the test overrides it.
  • commandTimeout is no longer final, so the test can shorten it.

The README's Develop section says how to run the tests.

Checks

  • ./gradlew spotlessCheck build passes in the gradle:9-jdk21 container; the tests take about 3 seconds.
  • Each test catches what it's for: with the code broken on purpose (no empty stdin, no version appended, no authorization check), promptGetsNoInput, versionIsAppendedToCommand, and otherUserCannotDeploy failed.

Found while writing the tests

A deploy request without a ver parameter throws a NullPointerException from Pattern.matcher(null) in DeployerFacade.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

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 slominskir left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly better than no tests...

@slominskir
slominskir merged commit 61e7051 into main Oct 1, 2026
5 checks passed
@slominskir
slominskir deleted the unit-tests branch October 1, 2026 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant