-
Notifications
You must be signed in to change notification settings - Fork 743
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Go] Paging tests and general paging fixes (#1489)
* Trying to delete duplication * Graph doesn't duplicate odatanextlink * OdataNextLink not duplicated and correctly named * Not needed preparers for paged results are no longer included in models file. This also causes that if there is already a next method defined in swagger for that model (including generic next methods), autorest wont generate the specific next links. * Added paging tests (except fragment link) * Added fragment next link test * Fixed code about preparer for pages types
- Loading branch information
1 parent
b24dfeb
commit 87cdf99
Showing
18 changed files
with
289 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
src/generator/AutoRest.Go.Tests/src/tests/acceptancetests/paginggrouptest/paging_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.