From 72adacdcaaadab40a66f91dd209011cb79b3535f Mon Sep 17 00:00:00 2001 From: Johan Brandhorst-Satzkorn Date: Tue, 24 Oct 2023 16:36:10 -0700 Subject: [PATCH] internal/tests: add target pagination test --- internal/tests/api/targets/target_test.go | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/internal/tests/api/targets/target_test.go b/internal/tests/api/targets/target_test.go index 508b01a8b5f..298cf7b8b46 100644 --- a/internal/tests/api/targets/target_test.go +++ b/internal/tests/api/targets/target_test.go @@ -242,6 +242,43 @@ func TestList(t *testing.T) { assert.Equal(filterItem.Id, ul.Items[0].Id) } +func TestListWithRefreshToken(t *testing.T) { + require := require.New(t) + tc := controller.NewTestController(t, nil) + defer tc.Shutdown() + + client := tc.Client() + token := tc.Token() + client.SetToken(token.Token) + _, proj := iam.TestScopes(t, tc.IamRepo(), iam.WithUserId(token.UserId)) + + tarClient := targets.NewClient(client) + _, err := tarClient.Create(tc.Context(), "tcp", proj.GetPublicId(), targets.WithName("1"), targets.WithTcpTargetDefaultPort(2)) + require.NoError(err) + _, err = tarClient.Create(tc.Context(), "tcp", proj.GetPublicId(), targets.WithName("2"), targets.WithTcpTargetDefaultPort(2)) + require.NoError(err) + + // Refresh tokens using project scope + res, err := tarClient.List(tc.Context(), proj.GetPublicId(), targets.WithRecursive(true)) + require.NoError(err) + require.Len(res.Items, 2, "expected the 2 targets created above") + refTok := res.RefreshToken + + res, err = tarClient.List(tc.Context(), proj.GetPublicId(), targets.WithRecursive(true), targets.WithRefreshToken(refTok)) + require.NoError(err) + require.Empty(res.Items) + + // Refresh tokens recursive listing over global scope + res, err = tarClient.List(tc.Context(), "global", targets.WithRecursive(true)) + require.NoError(err) + require.Len(res.Items, 4, "expected the 2 targets created above and the 2 auto created for the test controller") + refTok = res.RefreshToken + + res, err = tarClient.List(tc.Context(), "global", targets.WithRecursive(true), targets.WithRefreshToken(refTok)) + require.NoError(err) + require.Empty(res.Items) +} + func TestTarget_AddressMutualExclusiveRelationship(t *testing.T) { tc := controller.NewTestController(t, nil)