test(backend): increase apiserver/template test coverage to 64.5%#13203
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds comprehensive unit tests for 30+ previously untested functions and methods in the backend/src/apiserver/template/ package, significantly increasing test coverage from 40.1% to 61.9%. The tests include coverage for helper functions, trigger conversion, service account configuration, V2 pipeline job input validation, template constructors, and all simple Template interface methods including nil-receiver safety checks.
Changes:
- Added
structpbimport for protobuf value construction in tests - Added 446 lines of well-structured unit tests covering helper functions, template constructors, Template interface methods, nil-receiver safety, and validation logic
- Tests cover both happy paths and error conditions with meaningful assertions
|
/ok-to-test |
f1ec8a5 to
19eb4ac
Compare
|
/retest |
2 similar comments
|
/retest |
|
/retest |
jeffspahr
left a comment
There was a problem hiding this comment.
Reviewed the added coverage in backend/src/apiserver/template/template_test.go and found no blocking issues.
Verification:
- go test -v -cover ./backend/src/apiserver/template/...\n- go test -shuffle=on ./backend/src/apiserver/template
Both passed locally. I could not rerun golangci-lint in this environment because golangci-lint is not installed here.
|
/retest |
|
/lgtm |
|
/retest |
…o 61.9% Add unit tests for untested functions in the template package: - modelToPipelineJobRuntimeConfig: nil, empty, valid, and invalid JSON - StringMapToCRDParameters: empty, valid map, invalid JSON - stringArrayToCRDParameters: empty, valid array, invalid JSON - modelToParametersMap: empty, valid, invalid JSON - modelToCRDTrigger: periodic schedule and empty trigger paths - setDefaultServiceAccount: explicit and fallback-to-config paths - validatePipelineJobInputs: missing inputs, correct type, wrong type, extra params - NewArgoTemplate/NewArgoTemplateFromWorkflow constructors - Argo method coverage: GetTemplateType, Bytes, IsV2, V2PipelineName, OverrideV2PipelineName, ParametersJSON, IsCacheDisabled, nil receivers - V2Spec method coverage: GetTemplateType, IsV2, V2PipelineName, OverrideV2PipelineName, ParametersJSON, IsCacheDisabled, PipelineSpec, PlatformSpec, Bytes, nil receivers - NewV2SpecTemplate validation: empty input, invalid YAML - NewGenericScheduledWorkflow: full field verification - AddRuntimeMetadata: annotation and label checks - New factory: unknown format error path Signed-off-by: Jaison Paul <paul.jaison@gmail.com>
19eb4ac to
1fdc3d2
Compare
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hbelmiro The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Summary
backend/src/apiserver/template/modelToPipelineJobRuntimeConfig,StringMapToCRDParameters,stringArrayToCRDParameters,modelToParametersMap), trigger conversion (modelToCRDTriggerperiodic path), service account defaults, Argo/V2Spec constructors, and all simple Template interface methods including nil-receiver safetyvalidatePipelineJobInputscoverage: all parameter types (STRING, NUMBER_DOUBLE, BOOLEAN, LIST, STRUCT), error paths (UNSPECIFIED, TASK_FINAL_STATUS), optional params, extra params, missing required paramsCoverage: 40.1% → 64.5% (+24.4%)
Test plan
go test -v -cover ./backend/src/apiserver/template/— all tests pass, 64.5% coveragegolangci-lint run --new --new-from-merge-base=origin/master— 0 issuesgofmtapplied