-
Notifications
You must be signed in to change notification settings - Fork 742
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
[Go]Paging tests and general paging fixes #1489
Changes from 15 commits
4f32f7a
833a18a
fed81e8
b112e47
9d00153
76fb3f8
e59d03f
ff5f147
cc99dd5
c020616
7c0c403
b84d208
d68400c
092642b
f41e6b8
32e755b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package paginggrouptest | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
chk "gopkg.in/check.v1" | ||
|
||
"tests/acceptancetests/utils" | ||
. "tests/generated/paging" | ||
) | ||
|
||
func Test(t *testing.T) { chk.TestingT(t) } | ||
|
||
type PagingGroupSuite struct{} | ||
|
||
var _ = chk.Suite(&PagingGroupSuite{}) | ||
|
||
var pagingClient = getPagingClient() | ||
var clientID = "client-id" | ||
|
||
func getPagingClient() PagingClient { | ||
c := NewPagingClient() | ||
c.BaseURI = utils.GetBaseURI() | ||
return c | ||
} | ||
|
||
func (s *PagingGroupSuite) TestGetMultiplePages(c *chk.C) { | ||
res, err := pagingClient.GetMultiplePages(clientID, nil, nil) | ||
c.Assert(err, chk.IsNil) | ||
c.Assert(res.NextLink, chk.NotNil) | ||
count := 1 | ||
for res.NextLink != nil { | ||
count++ | ||
resNext, err := pagingClient.GetMultiplePagesNextResults(res) | ||
c.Assert(err, chk.IsNil) | ||
res = resNext | ||
} | ||
c.Assert(count, chk.Equals, 10) | ||
} | ||
|
||
func (s *PagingGroupSuite) TestGetSinglePages(c *chk.C) { | ||
res, err := pagingClient.GetSinglePages() | ||
c.Assert(err, chk.IsNil) | ||
c.Assert(res.NextLink, chk.IsNil) | ||
} | ||
|
||
func (s *PagingGroupSuite) TestGetOdataMultiplePages(c *chk.C) { | ||
res, err := pagingClient.GetOdataMultiplePages(clientID, nil, nil) | ||
c.Assert(err, chk.IsNil) | ||
c.Assert(res.OdataNextLink, chk.NotNil) | ||
count := 1 | ||
for res.OdataNextLink != nil { | ||
count++ | ||
resNext, err := pagingClient.GetOdataMultiplePagesNextResults(res) | ||
c.Assert(err, chk.IsNil) | ||
res = resNext | ||
} | ||
c.Assert(count, chk.Equals, 10) | ||
} | ||
|
||
func (s *PagingGroupSuite) TestGetMultiplePagesWithOffset(c *chk.C) { | ||
res, err := pagingClient.GetMultiplePagesWithOffset(100, clientID, nil, nil) | ||
c.Assert(err, chk.IsNil) | ||
c.Assert(res.NextLink, chk.NotNil) | ||
count := 1 | ||
for res.NextLink != nil { | ||
count++ | ||
resNext, err := pagingClient.GetMultiplePagesWithOffsetNextResults(res) | ||
c.Assert(err, chk.IsNil) | ||
res = resNext | ||
} | ||
c.Assert(count, chk.Equals, 10) | ||
c.Assert(*(*res.Values)[0].Properties.ID, chk.Equals, int32(110)) | ||
} | ||
|
||
func (s *PagingGroupSuite) TestGetMultiplePagesRetryFirst(c *chk.C) { | ||
res, err := pagingClient.GetMultiplePagesRetryFirst() | ||
c.Assert(err, chk.IsNil) | ||
count := 1 | ||
for res.NextLink != nil { | ||
count++ | ||
resNext, err := pagingClient.GetMultiplePagesRetryFirstNextResults(res) | ||
c.Assert(err, chk.IsNil) | ||
res = resNext | ||
} | ||
c.Assert(count, chk.Equals, 10) | ||
} | ||
|
||
func (s *PagingGroupSuite) TestGetMultiplePagesRetrySecond(c *chk.C) { | ||
res, err := pagingClient.GetMultiplePagesRetrySecond() | ||
c.Assert(err, chk.IsNil) | ||
count := 1 | ||
for res.NextLink != nil { | ||
count++ | ||
resNext, err := pagingClient.GetMultiplePagesRetrySecondNextResults(res) | ||
c.Assert(err, chk.IsNil) | ||
res = resNext | ||
} | ||
c.Assert(count, chk.Equals, 10) | ||
} | ||
|
||
func (s *PagingGroupSuite) TestGetSinglePagesFailure(c *chk.C) { | ||
res, err := pagingClient.GetSinglePagesFailure() | ||
c.Assert(err, chk.NotNil) | ||
c.Assert(res.StatusCode, chk.Equals, http.StatusBadRequest) | ||
} | ||
|
||
func (s *PagingGroupSuite) TestGetMultiplePagesFailure(c *chk.C) { | ||
res, err := pagingClient.GetMultiplePagesFailure() | ||
c.Assert(err, chk.IsNil) | ||
c.Assert(res.NextLink, chk.NotNil) | ||
res, err = pagingClient.GetMultiplePagesFailureNextResults(res) | ||
c.Assert(err, chk.NotNil) | ||
c.Assert(res.StatusCode, chk.Equals, http.StatusBadRequest) | ||
} | ||
|
||
func (s *PagingGroupSuite) TestGetMultiplePagesFailureURI(c *chk.C) { | ||
res, err := pagingClient.GetMultiplePagesFailureURI() | ||
c.Assert(err, chk.IsNil) | ||
c.Assert(*res.NextLink, chk.Equals, "*&*#&$") | ||
_, err = pagingClient.GetMultiplePagesFailureURINextResults(res) | ||
c.Assert(err, chk.NotNil) | ||
c.Assert(err, chk.ErrorMatches, ".*No scheme detected in URL.*") | ||
} | ||
|
||
func (s *PagingGroupSuite) TestGetMultiplePagesFragmentNextLink(c *chk.C) { | ||
res, err := pagingClient.GetMultiplePagesFragmentNextLink("1.6", "test_user") | ||
c.Assert(err, chk.IsNil) | ||
count := 1 | ||
for res.OdataNextLink != nil { | ||
count++ | ||
resNext, err := pagingClient.NextFragment("1.6", "test_user", *res.OdataNextLink) | ||
c.Assert(err, chk.IsNil) | ||
res = resNext | ||
} | ||
c.Assert(count, chk.Equals, 10) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,13 @@ | |
using System.Linq; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using Newtonsoft.Json; | ||
|
||
using AutoRest.Core.ClientModel; | ||
using AutoRest.Core.Utilities; | ||
using AutoRest.Go.TemplateModels; | ||
using AutoRest.Extensions.Azure; | ||
using AutoRest.Extensions.Azure.Model; | ||
|
||
namespace AutoRest.Go | ||
{ | ||
|
@@ -380,7 +382,7 @@ private static string GetSeparator(this CollectionFormat format) | |
|
||
public static bool IsClientProperty(this Parameter parameter) | ||
{ | ||
return parameter.ClientProperty != null; | ||
return parameter.ClientProperty != null || parameter.SerializedName.IsApiVersion(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please help me understand which bug you are resolving with this updates? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this line in particular, it is not so much about solving, but classifing APIversion as a Client property. Currently, I don't like that much how APIversion is handled by the generator, but I didn't want to poke that a lot in this PR. |
||
} | ||
|
||
public static string GetParameterName(this Parameter parameter) | ||
|
@@ -397,7 +399,7 @@ public static bool IsMethodArgument(this Parameter parameter) | |
|
||
public static bool IsApiVersion(this string name) | ||
{ | ||
string rgx = @"^api[^a-zA-Z0-9]?version"; | ||
string rgx = @"^api[^a-zA-Z0-9_]?version"; | ||
return Regex.IsMatch(name, rgx, RegexOptions.IgnoreCase); | ||
} | ||
|
||
|
@@ -560,7 +562,13 @@ public static string Fields(this CompositeType compositeType) | |
&& !String.IsNullOrEmpty((compositeType as ModelTemplateModel).NextLink)) | ||
{ | ||
var nextLinkField = (compositeType as ModelTemplateModel).NextLink; | ||
if (!properties.Any(p => p.Name == nextLinkField)) | ||
foreach (Property p in properties) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment explaining why this is necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This foreach removes all dots in properties (for code to work), and if it finds the already existing next link, changes its name to how NextLink was added originally (NextLink is a ModelTemplateModel property and it is used in more places, including the razor tamplates) |
||
p.Name = GoCodeNamer.PascalCaseWithoutChar(p.Name, '.'); | ||
if (p.Name.Equals(nextLinkField, StringComparison.OrdinalIgnoreCase)) { | ||
p.Name = nextLinkField; | ||
} | ||
} | ||
if (!properties.Any(p => p.Name.Equals(nextLinkField, StringComparison.OrdinalIgnoreCase))) | ||
{ | ||
var property = new Property(); | ||
property.Name = nextLinkField; | ||
|
@@ -983,6 +991,24 @@ public static bool IsPageable(this Method method) | |
return !string.IsNullOrEmpty(method.NextLink()); | ||
} | ||
|
||
/// <summary> | ||
/// Checks if method for next page of results on paged methods is already present in the method list. | ||
/// </summary> | ||
/// <param name="method"></param> | ||
/// <param name="methods"></param> | ||
/// <returns></returns> | ||
public static bool NextMethodExists(this Method method, List<Method> methods) { | ||
if (method.Extensions.ContainsKey(AzureExtensions.PageableExtension)) | ||
{ | ||
var pageableExtension = JsonConvert.DeserializeObject<PageableExtension>(method.Extensions[AzureExtensions.PageableExtension].ToString()); | ||
if (pageableExtension != null && !string.IsNullOrWhiteSpace(pageableExtension.OperationName)) | ||
{ | ||
return methods.Any(m => m.SerializedName.Equals(pageableExtension.OperationName, StringComparison.OrdinalIgnoreCase)); | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/// <summary> | ||
/// Check if method has long running extension (x-ms-long-running-operation) enabled. | ||
/// </summary> | ||
|
@@ -1022,7 +1048,7 @@ public static string NextLink(this Method method) | |
var nextLinkName = (string)pageableExtension["nextLinkName"]; | ||
if (!string.IsNullOrEmpty(nextLinkName)) | ||
{ | ||
nextLink = GoCodeNamer.PascalCase(nextLinkName); | ||
nextLink = GoCodeNamer.PascalCaseWithoutChar(nextLinkName, '.'); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, PascalCase is not removing dots from names. I added this function so it removes dots too. |
||
} | ||
} | ||
|
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.
With this changes, should we update https://github.com/Azure/autorest/blob/master/Documentation/building-code.md ?
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.
Ah, yes we should. Install Golang and glide.