Improve WSDL-generated file parity with webservice.go - #641
Conversation
Signed-off-by: Antonio Gamez Diaz <antonio.gamez@suse.com>
Signed-off-by: Antonio Gamez Diaz <antonio.gamez@suse.com>
Signed-off-by: Antonio Gamez Diaz <antonio.gamez@suse.com>
|
@arbulu89, the regardless of the tests (we can add them or not, no strong opinions here), I'd like to double-check if the drift is intentional or if it is an actual error: The manually generated file has: err := s.client.CallContext(ctx, "''", request, &response) // note the pointer &but in the autogenerated, the proper signature seems to be: err := s.client.CallContext(ctx, "''", request, response)This is the proposed fix: be5ddcc (I've removed it so that the test actually fails in CI) |
There was a problem hiding this comment.
🟡 Not ready to approve
The implementation still passes &response into CallContext for some operations, which breaks decoding and will cause the newly added parity/unit tests to fail.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Pull request overview
This PR adds test coverage and drift-detection for the hand-written sapcontrolapi SOAP client to keep it aligned with the WSDL-generated reference, and refreshes contributor guidance for regenerating and validating the WSDL code.
Changes:
- Added a fake-SOAP-server based unit test suite covering the currently supported
WebServiceoperations. - Added an AST-based parity test that compares
webservice.gotypes/method signatures against_generated_wsdl.go. - Updated SAPControl client README with WSDL regeneration and testing instructions; adjusted
HAGetFailoverConfigResponseto match generated XML shape and added a test-friendly constructor.
File summaries
| File | Description |
|---|---|
| internal/core/sapsystem/sapcontrolapi/webservice.go | Removes a drifting XMLName tag from HAGetFailoverConfigResponse and adds NewWebServiceFromClient to allow injecting a SOAP client (used by tests). |
| internal/core/sapsystem/sapcontrolapi/webservice_test.go | Introduces unit tests using httptest to validate request/response decoding for supported operations and basic HTTP error handling. |
| internal/core/sapsystem/sapcontrolapi/parity_test.go | Adds a parity test that parses Go AST to ensure the hand-written subset remains aligned with the generated WSDL reference (types, enums, and response passing to CallContext). |
| internal/core/sapsystem/sapcontrolapi/README.md | Expands contributor documentation for regenerating _generated_wsdl.go, running tests, and adding new operations. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 4
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
There was a problem hiding this comment.
Hey @antgamdia ,
Do we need to touch these thing?
I personally would vote to keep as it is. I find really little value, just add tests to "cover" code. I don't think we need to test auto-generated code.
arbulu89
left a comment
There was a problem hiding this comment.
Green light!
I guess you will change the %response to response in the pointers that are wrong before mergint
|
As shared offline, it turns out the double-pointer issue is, thankfully, harmless IRL due to a guard in the XML decoder: func (d *Decoder) DecodeElement(v any, start *StartElement) error {
val := reflect.ValueOf(v)
if val.Kind() != reflect.Pointer { return errors.New("non-pointer passed to Unmarshal") }
if val.IsNil() { return errors.New("nil pointer passed to Unmarshal") }
return d.unmarshal(val.Elem(), start, 0) // <-- dereferences ONE level, unconditionally
}
func (d *Decoder) unmarshal(val reflect.Value, start *StartElement, depth int) error {
...
if val.Kind() == reflect.Pointer {
if val.IsNil() { val.Set(reflect.New(val.Type().Elem())) }
val = val.Elem() // <-- dereferences again, only if still a pointer
}
// from here val is finally the Struct, whichever path got here |
Signed-off-by: Antonio Gamez Diaz <antonio.gamez@suse.com>
Signed-off-by: Antonio Gamez Diaz <antonio.gamez@suse.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (2)
internal/core/sapsystem/sapcontrolapi/README.md:24
- The generation instructions still refer to copying from
sapcontrol/_generated_wsdl.go, but the command above generates_generated_wsdl.godirectly (and the package issapcontrolapi). As written, the path is misleading for contributors.
# Copy the code from sapcontrol/_generated_wsdl.go to your final destination
internal/core/sapsystem/sapcontrolapi/README.md:29
- Typo in the link text: "How to user" should be "How to use".
- [How to user the SAPControl Web Service Interface](https://www.sap.com/documents/2016/09/0a40e60d-8b7c-0010-82c7-eda71af511fa.html)
Signed-off-by: Antonio Gamez Diaz <antonio.gamez@suse.com>
|
@arbulu89 , I have reduced the scope of this PR, removing the reflection-based test and leaving the one spinning up the fake SOAP server. I think it is a good tradeoff between coverage and test complexity.
Done at a8d37c4 :) |
Description
This pull request improves the testability and reliability of the
sapcontrolapiweb service package by introducing a new test suite, fixing response handling in certain methods, and clarifying documentation.Testing improvements:
webservice_test.gocontaining comprehensive unit tests for all main operations of theWebServiceinterface, including both typical and error scenarios. These tests use a local HTTP server to simulate SOAP responses and verify correct parsing and error handling.NewWebServiceFromClientconstructor inwebservice.goto allow injecting a custom or mocked SOAP client, improving testability and enabling the new unit tests.Bug fixes:
CallContextmethod inHACheckConfigContextandHAGetFailoverConfigContextto pass the response object directly, ensuring correct unmarshaling of SOAP responses.Documentation updates:
README.mdto clarify that the simplified web service implementation is inwebservice.goand that matching tests are now provided inwebservice_test.go. Also improved instructions for generating WSDL code and fixed the output file naming.Minor cleanup:
XMLNamefield from theHAGetFailoverConfigResponsestruct, as it is not required for decoding the response.How was this tested?
UT
Documentation changes
No
Additional information
It previously had a complex test parsing the go file and checking the parity between the autogenerated and the simplified version, but, for now, we're not adding it.