Skip to content

Improve WSDL-generated file parity with webservice.go - #641

Open
antgamdia wants to merge 9 commits into
mainfrom
fix-wsdl-parity
Open

Improve WSDL-generated file parity with webservice.go#641
antgamdia wants to merge 9 commits into
mainfrom
fix-wsdl-parity

Conversation

@antgamdia

@antgamdia antgamdia commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Description

This pull request improves the testability and reliability of the sapcontrolapi web service package by introducing a new test suite, fixing response handling in certain methods, and clarifying documentation.

Testing improvements:

  • Added a new file webservice_test.go containing comprehensive unit tests for all main operations of the WebService interface, including both typical and error scenarios. These tests use a local HTTP server to simulate SOAP responses and verify correct parsing and error handling.
  • Introduced the NewWebServiceFromClient constructor in webservice.go to allow injecting a custom or mocked SOAP client, improving testability and enabling the new unit tests.

Bug fixes:

  • Fixed the use of the CallContext method in HACheckConfigContext and HAGetFailoverConfigContext to pass the response object directly, ensuring correct unmarshaling of SOAP responses.

Documentation updates:

  • Updated the README.md to clarify that the simplified web service implementation is in webservice.go and that matching tests are now provided in webservice_test.go. Also improved instructions for generating WSDL code and fixed the output file naming.

Minor cleanup:

  • Removed an unnecessary XMLName field from the HAGetFailoverConfigResponse struct, 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.

Signed-off-by: Antonio Gamez Diaz <antonio.gamez@suse.com>
@antgamdia antgamdia added the enhancement New feature or request label Jul 22, 2026
Signed-off-by: Antonio Gamez Diaz <antonio.gamez@suse.com>
Signed-off-by: Antonio Gamez Diaz <antonio.gamez@suse.com>
Comment thread internal/core/sapsystem/sapcontrolapi/webservice.go Outdated
Comment thread internal/core/sapsystem/sapcontrolapi/webservice.go Outdated
Comment thread internal/core/sapsystem/sapcontrolapi/webservice.go
@antgamdia
antgamdia requested a review from arbulu89 July 22, 2026 14:20
@antgamdia antgamdia added chore and removed enhancement New feature or request labels Jul 22, 2026
@antgamdia antgamdia changed the title Ensure WSDL-generated file parirty with webservice.go Ensure WSDL-generated file parity with webservice.go Jul 22, 2026
Signed-off-by: Antonio Gamez Diaz <antonio.gamez@suse.com>
@antgamdia

Copy link
Copy Markdown
Contributor Author

@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)

Copilot AI 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.

🟡 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 WebService operations.
  • Added an AST-based parity test that compares webservice.go types/method signatures against _generated_wsdl.go.
  • Updated SAPControl client README with WSDL regeneration and testing instructions; adjusted HAGetFailoverConfigResponse to 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.

Comment thread internal/core/sapsystem/sapcontrolapi/webservice.go
Comment thread internal/core/sapsystem/sapcontrolapi/README.md Outdated
Comment thread internal/core/sapsystem/sapcontrolapi/README.md Outdated
Comment thread internal/core/sapsystem/sapcontrolapi/README.md Outdated

@arbulu89 arbulu89 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.

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 arbulu89 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.

Green light!
I guess you will change the %response to response in the pointers that are wrong before mergint

@antgamdia

Copy link
Copy Markdown
Contributor Author

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>
@antgamdia antgamdia changed the title Ensure WSDL-generated file parity with webservice.go Improve WSDL-generated file parity with webservice.go Aug 18, 2026
@antgamdia
antgamdia requested a lite review from Copilot August 18, 2026 16:01

Copilot AI 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.

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.go directly (and the package is sapcontrolapi). 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>
@antgamdia

Copy link
Copy Markdown
Contributor Author

@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.

I guess you will change the &response to response in the pointers that are wrong before merging

Done at a8d37c4 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants