Skip to content

Add some tests - #5

Merged
wkoszek merged 14 commits into
mainfrom
add-some-tests
Nov 20, 2025
Merged

Add some tests#5
wkoszek merged 14 commits into
mainfrom
add-some-tests

Conversation

@yusufmalikul

@yusufmalikul yusufmalikul commented Oct 30, 2025

Copy link
Copy Markdown
Collaborator

This PR adds a comprehensive test suite to the bsubio-go SDK, significantly improving code maintainability, reliability, and confidence in future changes. The test suite provides 38.4% code coverage with a focus on critical client functionality.

What's Changed:

  • Added client_test.go of comprehensive tests
  • 40 test cases covering all major SDK functionality
  • All tests passing with no failures
  • Mock HTTP server infrastructure using httptest
✗ go test ./... -p 1 -v -cover
=== RUN   TestNewBsubClient
=== RUN   TestNewBsubClient/valid_config_with_defaults
=== RUN   TestNewBsubClient/valid_config_with_custom_base_URL
=== RUN   TestNewBsubClient/valid_config_with_custom_HTTP_client
=== RUN   TestNewBsubClient/missing_API_key
=== RUN   TestNewBsubClient/empty_API_key
--- PASS: TestNewBsubClient (0.00s)
    --- PASS: TestNewBsubClient/valid_config_with_defaults (0.00s)
    --- PASS: TestNewBsubClient/valid_config_with_custom_base_URL (0.00s)
    --- PASS: TestNewBsubClient/valid_config_with_custom_HTTP_client (0.00s)
    --- PASS: TestNewBsubClient/missing_API_key (0.00s)
    --- PASS: TestNewBsubClient/empty_API_key (0.00s)
=== RUN   TestNewBsubClient_AuthInterceptor
--- PASS: TestNewBsubClient_AuthInterceptor (0.00s)
=== RUN   TestCreateAndSubmitJob
=== RUN   TestCreateAndSubmitJob/successful_job_creation_and_submission
=== RUN   TestCreateAndSubmitJob/job_creation_fails
=== RUN   TestCreateAndSubmitJob/upload_fails
=== RUN   TestCreateAndSubmitJob/submit_fails
--- PASS: TestCreateAndSubmitJob (0.00s)
    --- PASS: TestCreateAndSubmitJob/successful_job_creation_and_submission (0.00s)
    --- PASS: TestCreateAndSubmitJob/job_creation_fails (0.00s)
    --- PASS: TestCreateAndSubmitJob/upload_fails (0.00s)
    --- PASS: TestCreateAndSubmitJob/submit_fails (0.00s)
=== RUN   TestWaitForJob
=== RUN   TestWaitForJob/job_finishes_successfully
=== RUN   TestWaitForJob/job_fails
=== RUN   TestWaitForJob/context_cancellation
=== RUN   TestWaitForJob/HTTP_error_during_polling
--- PASS: TestWaitForJob (4.11s)
    --- PASS: TestWaitForJob/job_finishes_successfully (4.00s)
    --- PASS: TestWaitForJob/job_fails (0.00s)
    --- PASS: TestWaitForJob/context_cancellation (0.10s)
    --- PASS: TestWaitForJob/HTTP_error_during_polling (0.00s)
=== RUN   TestGetJobResult
=== RUN   TestGetJobResult/successful_result_retrieval
=== RUN   TestGetJobResult/failed_job_retrieval
=== RUN   TestGetJobResult/output_retrieval_returns_non-200_-_handled_gracefully
=== RUN   TestGetJobResult/logs_retrieval_fails_gracefully
--- PASS: TestGetJobResult (0.00s)
    --- PASS: TestGetJobResult/successful_result_retrieval (0.00s)
    --- PASS: TestGetJobResult/failed_job_retrieval (0.00s)
    --- PASS: TestGetJobResult/output_retrieval_returns_non-200_-_handled_gracefully (0.00s)
    --- PASS: TestGetJobResult/logs_retrieval_fails_gracefully (0.00s)
=== RUN   TestProcess
=== RUN   TestProcess/successful_processing
=== RUN   TestProcess/job_fails_during_processing
--- PASS: TestProcess (0.00s)
    --- PASS: TestProcess/successful_processing (0.00s)
    --- PASS: TestProcess/job_fails_during_processing (0.00s)
=== RUN   TestCreateAndSubmitJobFromFile
=== RUN   TestCreateAndSubmitJobFromFile/successful_file_processing
=== RUN   TestCreateAndSubmitJobFromFile/file_not_found
--- PASS: TestCreateAndSubmitJobFromFile (0.00s)
    --- PASS: TestCreateAndSubmitJobFromFile/successful_file_processing (0.00s)
    --- PASS: TestCreateAndSubmitJobFromFile/file_not_found (0.00s)
=== RUN   TestProcessFile
=== RUN   TestProcessFile/successful_file_processing_end-to-end
--- PASS: TestProcessFile (0.00s)
    --- PASS: TestProcessFile/successful_file_processing_end-to-end (0.00s)
=== RUN   TestJobStatus
--- PASS: TestJobStatus (0.00s)
=== RUN   TestJobIsTerminal
=== RUN   TestJobIsTerminal/created
=== RUN   TestJobIsTerminal/loaded
=== RUN   TestJobIsTerminal/pending
=== RUN   TestJobIsTerminal/claimed
=== RUN   TestJobIsTerminal/preparing
=== RUN   TestJobIsTerminal/processing
=== RUN   TestJobIsTerminal/finished
=== RUN   TestJobIsTerminal/failed
--- PASS: TestJobIsTerminal (0.00s)
    --- PASS: TestJobIsTerminal/created (0.00s)
    --- PASS: TestJobIsTerminal/loaded (0.00s)
    --- PASS: TestJobIsTerminal/pending (0.00s)
    --- PASS: TestJobIsTerminal/claimed (0.00s)
    --- PASS: TestJobIsTerminal/preparing (0.00s)
    --- PASS: TestJobIsTerminal/processing (0.00s)
    --- PASS: TestJobIsTerminal/finished (0.00s)
    --- PASS: TestJobIsTerminal/failed (0.00s)
PASS
coverage: 38.4% of statements
ok      github.com/bsubio/bsubio-go     (cached)        coverage: 38.4% of statements
        github.com/bsubio/bsubio-go/examples/basic              coverage: 0.0% of statements
        github.com/bsubio/bsubio-go/examples/batch              coverage: 0.0% of statements
        github.com/bsubio/bsubio-go/examples/comprehensive              coverage: 0.0% of statements
        github.com/bsubio/bsubio-go/examples/custom-workflow            coverage: 0.0% of statements

This was linked to issues Oct 30, 2025
@yusufmalikul
yusufmalikul requested a review from wkoszek October 30, 2025 12:19
@yusufmalikul
yusufmalikul marked this pull request as ready for review October 30, 2025 12:23
@wkoszek

wkoszek commented Oct 31, 2025

Copy link
Copy Markdown
Contributor

@yusufmalikul The unit tests that re-do pieces of the code just to reply back correctly to the SDK ... will always pass?

What we've essentially done here is a mock server that always replies exactly what we want. There's a value in this. But let's perhaps just write it as mock server that serves mock requests.

And the unit test suite with arrays of conditions could be separate.

Then I'd like to be able to do 2 things:

  • play tests against mock server
  • play tests against prod server.

This would be immensely valuable. We could assume that those tests would read ~/.config/bsub/config.json perhaps for a proper API key cases? For proper testing, I think we should assume some mocky types of jobs.

For example: passthrough job could be used, or line_counter job etc.

@wkoszek wkoszek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Put comment on the PR

@yusufmalikul

Copy link
Copy Markdown
Collaborator Author

@wkoszek added test against prod server.

@wkoszek
wkoszek merged commit 9fe6739 into main Nov 20, 2025
1 check passed
@yusufmalikul
yusufmalikul deleted the add-some-tests branch November 20, 2025 15:15
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.

Lets use UUID so SDK won't break Add some tests

2 participants