-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to pass and override default hard coded api version #274
Conversation
…ersion Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Essentially documentation asks. Please also add a changelog entry.
Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
govcd/api.go
Outdated
@@ -188,6 +196,12 @@ func (cli *Client) NewRequest(params map[string]string, method string, reqUrl ur | |||
return cli.NewRequestWitNotEncodedParams(params, nil, method, reqUrl, body) | |||
} | |||
|
|||
// NewRequest creates a new HTTP request and applies necessary auth headers if set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// NewRequest creates a new HTTP request and applies necessary auth headers if set. | |
// NewRequestWithApiVersion creates a new HTTP request and applies necessary auth headers if set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
udpated
@@ -127,6 +129,12 @@ func ContainsNotFound(err error) bool { | |||
|
|||
// NewRequestWitNotEncodedParams allows passing complex values params that shouldn't be encoded like for queries. e.g. /query?filter=name=foo | |||
func (cli *Client) NewRequestWitNotEncodedParams(params map[string]string, notEncodedParams map[string]string, method string, reqUrl url.URL, body io.Reader) *http.Request { | |||
return cli.NewRequestWitNotEncodedParamsWithApiVersion(params, notEncodedParams, method, reqUrl, body, cli.APIVersion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see a few tests for the new functions, to make sure that:
- They are really using the intended API version.
- Subsequent requests using the regular
Execute*
methods are not affected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you share your idea how to test that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a possible way:
- Add fields to a type that was enhanced in API versions later than the current one.
- Run a GET that retrieves the type with the enhanced fields
- Make sure the fields are non-empty
- Run the same query without the new API version
- Make sure that the enhanced fields are empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two more ideas:
- https://golang.org/pkg/net/http/httptest/
or - IIRC when you send a request on a specific version, vCD responds with API version (in headers). You could probably check that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first option could be valid with on specific vCD version or I have to find valid for all versions, which is lottery
I'll check possibility with response headers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test added
Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would also like to see a test hitting the new API-version-override ability, LGTM otherwise.
Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am happy with it, just as well. The only thing - would be good to have some test as Giuseppe mentioned.
Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com> # Conflicts: # CHANGELOG.md
Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
|
||
// Test_NewRequestWitNotEncodedParamsWithApiVersion verifies that api version override works | ||
func (vcd *TestVCD) Test_NewRequestWitNotEncodedParamsWithApiVersion(check *C) { | ||
fmt.Printf("Running: %s\n", check.TestName()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double check the outputs as they are missing new lines. Heres' how it looks.
START: api_test.go:105: TestVCD.Test_NewRequestWitNotEncodedParamsWithApiVersion
Running: TestVCD.Test_NewRequestWitNotEncodedParamsWithApiVersion
Test: TestVCD.Test_NewRequestWitNotEncodedParamsWithApiVersion run with api Version: 33.0
PASS: api_test.go:105: TestVCD.Test_NewRequestWitNotEncodedParamsWithApiVersion 0.191s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. This is fine as it is as planned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested the particular function on 9.0, 9.5 and 10. All worked.
The only ask is to fix the outputs.
Signed-off-by: Vaidotas Bauzys <vbauzys@vmware.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This change is driven from VM internal disk PR(#272) and investigation. Also we saw need that in near feature in other cases, as we face more such cases when we need specific version due limitation of using lowest possible API version.
WithApiVersion
which allows to pass API version which will be written in request header(override default hard coded one)We need override only per request base API version. Changing connection API version would create compatibility issues and breakage.