Skip to content

Commit

Permalink
Rename asyncpoller package to async
Browse files Browse the repository at this point in the history
  • Loading branch information
mboersma committed Sep 14, 2023
1 parent a521b7b commit e5e60ff
Show file tree
Hide file tree
Showing 70 changed files with 522 additions and 522 deletions.
6 changes: 3 additions & 3 deletions azure/services/agentpools/agentpools.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"k8s.io/utils/ptr"
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-azure/azure"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/asyncpoller"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/async"
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)
Expand Down Expand Up @@ -52,7 +52,7 @@ type AgentPoolScope interface {
// Service provides operations on Azure resources.
type Service struct {
scope AgentPoolScope
asyncpoller.Reconciler
async.Reconciler
}

// New creates a new service.
Expand All @@ -63,7 +63,7 @@ func New(scope AgentPoolScope) (*Service, error) {
}
return &Service{
scope: scope,
Reconciler: asyncpoller.New[armcontainerservice.AgentPoolsClientCreateOrUpdateResponse,
Reconciler: async.New[armcontainerservice.AgentPoolsClientCreateOrUpdateResponse,

Check warning on line 66 in azure/services/agentpools/agentpools.go

View check run for this annotation

Codecov / codecov/patch

azure/services/agentpools/agentpools.go#L66

Added line #L66 was not covered by tests
armcontainerservice.AgentPoolsClientDeleteResponse](scope, client, client),
}, nil
}
Expand Down
24 changes: 12 additions & 12 deletions azure/services/agentpools/agentpools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"k8s.io/utils/ptr"
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/agentpools/mock_agentpools"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/asyncpoller/mock_asyncpoller"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/async/mock_async"
gomockinternal "sigs.k8s.io/cluster-api-provider-azure/internal/test/matchers/gomock"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)
Expand All @@ -38,12 +38,12 @@ func TestReconcileAgentPools(t *testing.T) {
testcases := []struct {
name string
expectedError string
expect func(s *mock_agentpools.MockAgentPoolScopeMockRecorder, r *mock_asyncpoller.MockReconcilerMockRecorder)
expect func(s *mock_agentpools.MockAgentPoolScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder)
}{
{
name: "agent pool successfully created with autoscaling enabled",
expectedError: "",
expect: func(s *mock_agentpools.MockAgentPoolScopeMockRecorder, r *mock_asyncpoller.MockReconcilerMockRecorder) {
expect: func(s *mock_agentpools.MockAgentPoolScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
fakeAgentPoolSpec := fakeAgentPool()
s.AgentPoolSpec().Return(&fakeAgentPoolSpec)
r.CreateOrUpdateResource(gomockinternal.AContext(), &fakeAgentPoolSpec, serviceName).Return(sdkFakeAgentPool(sdkWithAutoscaling(true), sdkWithCount(1)), nil)
Expand All @@ -55,7 +55,7 @@ func TestReconcileAgentPools(t *testing.T) {
{
name: "agent pool successfully created with autoscaling disabled",
expectedError: "",
expect: func(s *mock_agentpools.MockAgentPoolScopeMockRecorder, r *mock_asyncpoller.MockReconcilerMockRecorder) {
expect: func(s *mock_agentpools.MockAgentPoolScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
fakeAgentPoolSpec := fakeAgentPool()
s.AgentPoolSpec().Return(&fakeAgentPoolSpec)
r.CreateOrUpdateResource(gomockinternal.AContext(), &fakeAgentPoolSpec, serviceName).Return(sdkFakeAgentPool(sdkWithAutoscaling(false), sdkWithCount(1)), nil)
Expand All @@ -67,14 +67,14 @@ func TestReconcileAgentPools(t *testing.T) {
{
name: "no agent pool spec found",
expectedError: "",
expect: func(s *mock_agentpools.MockAgentPoolScopeMockRecorder, r *mock_asyncpoller.MockReconcilerMockRecorder) {
expect: func(s *mock_agentpools.MockAgentPoolScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
s.AgentPoolSpec().Return(nil)
},
},
{
name: "fail to create a agent pool",
expectedError: internalError.Error(),
expect: func(s *mock_agentpools.MockAgentPoolScopeMockRecorder, r *mock_asyncpoller.MockReconcilerMockRecorder) {
expect: func(s *mock_agentpools.MockAgentPoolScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
fakeAgentPoolSpec := fakeAgentPool()
s.AgentPoolSpec().Return(&fakeAgentPoolSpec)
r.CreateOrUpdateResource(gomockinternal.AContext(), &fakeAgentPoolSpec, serviceName).Return(nil, internalError)
Expand All @@ -91,7 +91,7 @@ func TestReconcileAgentPools(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
scopeMock := mock_agentpools.NewMockAgentPoolScope(mockCtrl)
asyncMock := mock_asyncpoller.NewMockReconciler(mockCtrl)
asyncMock := mock_async.NewMockReconciler(mockCtrl)

tc.expect(scopeMock.EXPECT(), asyncMock.EXPECT())

Expand All @@ -115,12 +115,12 @@ func TestDeleteAgentPools(t *testing.T) {
testcases := []struct {
name string
expectedError string
expect func(s *mock_agentpools.MockAgentPoolScopeMockRecorder, r *mock_asyncpoller.MockReconcilerMockRecorder)
expect func(s *mock_agentpools.MockAgentPoolScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder)
}{
{
name: "existing agent pool successfully deleted",
expectedError: "",
expect: func(s *mock_agentpools.MockAgentPoolScopeMockRecorder, r *mock_asyncpoller.MockReconcilerMockRecorder) {
expect: func(s *mock_agentpools.MockAgentPoolScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
fakeAgentPoolSpec := fakeAgentPool()
s.AgentPoolSpec().Return(&fakeAgentPoolSpec)
r.DeleteResource(gomockinternal.AContext(), &fakeAgentPoolSpec, serviceName).Return(nil)
Expand All @@ -130,14 +130,14 @@ func TestDeleteAgentPools(t *testing.T) {
{
name: "no agent pool spec found",
expectedError: "",
expect: func(s *mock_agentpools.MockAgentPoolScopeMockRecorder, r *mock_asyncpoller.MockReconcilerMockRecorder) {
expect: func(s *mock_agentpools.MockAgentPoolScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
s.AgentPoolSpec().Return(nil)
},
},
{
name: "fail to delete a agent pool",
expectedError: internalError.Error(),
expect: func(s *mock_agentpools.MockAgentPoolScopeMockRecorder, r *mock_asyncpoller.MockReconcilerMockRecorder) {
expect: func(s *mock_agentpools.MockAgentPoolScopeMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
fakeAgentPoolSpec := fakeAgentPool()
s.AgentPoolSpec().Return(&fakeAgentPoolSpec)
r.DeleteResource(gomockinternal.AContext(), &fakeAgentPoolSpec, serviceName).Return(internalError)
Expand All @@ -154,7 +154,7 @@ func TestDeleteAgentPools(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
scopeMock := mock_agentpools.NewMockAgentPoolScope(mockCtrl)
asyncMock := mock_asyncpoller.NewMockReconciler(mockCtrl)
asyncMock := mock_async.NewMockReconciler(mockCtrl)

tc.expect(scopeMock.EXPECT(), asyncMock.EXPECT())

Expand Down
6 changes: 3 additions & 3 deletions azure/services/agentpools/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v4"
"github.com/pkg/errors"
"sigs.k8s.io/cluster-api-provider-azure/azure"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/asyncpoller"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/async"
"sigs.k8s.io/cluster-api-provider-azure/util/reconciler"
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
)
Expand Down Expand Up @@ -89,7 +89,7 @@ func (ac *azureClient) CreateOrUpdateAsync(ctx context.Context, spec azure.Resou
ctx, cancel := context.WithTimeout(ctx, reconciler.DefaultAzureCallTimeout)
defer cancel()

pollOpts := &runtime.PollUntilDoneOptions{Frequency: asyncpoller.DefaultPollerFrequency}
pollOpts := &runtime.PollUntilDoneOptions{Frequency: async.DefaultPollerFrequency}

Check warning on line 92 in azure/services/agentpools/client.go

View check run for this annotation

Codecov / codecov/patch

azure/services/agentpools/client.go#L92

Added line #L92 was not covered by tests
resp, err := poller.PollUntilDone(ctx, pollOpts)
if err != nil {
// If an error occurs, return the poller.
Expand Down Expand Up @@ -118,7 +118,7 @@ func (ac *azureClient) DeleteAsync(ctx context.Context, spec azure.ResourceSpecG
ctx, cancel := context.WithTimeout(ctx, reconciler.DefaultAzureCallTimeout)
defer cancel()

pollOpts := &runtime.PollUntilDoneOptions{Frequency: asyncpoller.DefaultPollerFrequency}
pollOpts := &runtime.PollUntilDoneOptions{Frequency: async.DefaultPollerFrequency}

Check warning on line 121 in azure/services/agentpools/client.go

View check run for this annotation

Codecov / codecov/patch

azure/services/agentpools/client.go#L121

Added line #L121 was not covered by tests
_, err = poller.PollUntilDone(ctx, pollOpts)
if err != nil {
// If an error occurs, return the poller.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package asyncpoller
package async

import (
"context"
Expand Down Expand Up @@ -54,7 +54,7 @@ func New[C, D any](scope FutureScope, createClient Creator[C], deleteClient Dele

// CreateOrUpdateResource creates a new resource or updates an existing one asynchronously.
func (s *Service[C, D]) CreateOrUpdateResource(ctx context.Context, spec azure.ResourceSpecGetter, serviceName string) (result interface{}, err error) {
ctx, log, done := tele.StartSpanWithLogger(ctx, "asyncpoller.Service.CreateOrUpdateResource")
ctx, log, done := tele.StartSpanWithLogger(ctx, "async.Service.CreateOrUpdateResource")
defer done()

resourceName := spec.ResourceName()
Expand Down Expand Up @@ -126,7 +126,7 @@ func (s *Service[C, D]) CreateOrUpdateResource(ctx context.Context, spec azure.R

// DeleteResource deletes a resource asynchronously.
func (s *Service[C, D]) DeleteResource(ctx context.Context, spec azure.ResourceSpecGetter, serviceName string) (err error) {
ctx, log, done := tele.StartSpanWithLogger(ctx, "asyncpoller.Service.DeleteResource")
ctx, log, done := tele.StartSpanWithLogger(ctx, "async.Service.DeleteResource")
defer done()

resourceName := spec.ResourceName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package asyncpoller
package async

import (
"context"
Expand All @@ -35,7 +35,7 @@ import (
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-azure/azure"
"sigs.k8s.io/cluster-api-provider-azure/azure/mock_azure"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/asyncpoller/mock_asyncpoller"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/async/mock_async"
gomockinternal "sigs.k8s.io/cluster-api-provider-azure/internal/test/matchers/gomock"
)

Expand All @@ -45,13 +45,13 @@ func TestServiceCreateOrUpdateResource(t *testing.T) {
serviceName string
expectedError string
expectedResult interface{}
expect func(g *WithT, s *mock_asyncpoller.MockFutureScopeMockRecorder, c *mock_asyncpoller.MockCreatorMockRecorder[MockCreator], r *mock_azure.MockResourceSpecGetterMockRecorder)
expect func(g *WithT, s *mock_async.MockFutureScopeMockRecorder, c *mock_async.MockCreatorMockRecorder[MockCreator], r *mock_azure.MockResourceSpecGetterMockRecorder)
}{
{
name: "invalid future",
serviceName: serviceName,
expectedError: "could not decode future data, resetting long-running operation state",
expect: func(g *WithT, s *mock_asyncpoller.MockFutureScopeMockRecorder, c *mock_asyncpoller.MockCreatorMockRecorder[MockCreator], r *mock_azure.MockResourceSpecGetterMockRecorder) {
expect: func(g *WithT, s *mock_async.MockFutureScopeMockRecorder, c *mock_async.MockCreatorMockRecorder[MockCreator], r *mock_azure.MockResourceSpecGetterMockRecorder) {
gomock.InOrder(
r.ResourceName().Return(resourceName),
r.ResourceGroupName().Return(resourceGroupName),
Expand All @@ -65,7 +65,7 @@ func TestServiceCreateOrUpdateResource(t *testing.T) {
serviceName: serviceName,
expectedError: "",
expectedResult: fakeResource,
expect: func(g *WithT, s *mock_asyncpoller.MockFutureScopeMockRecorder, c *mock_asyncpoller.MockCreatorMockRecorder[MockCreator], r *mock_azure.MockResourceSpecGetterMockRecorder) {
expect: func(g *WithT, s *mock_async.MockFutureScopeMockRecorder, c *mock_async.MockCreatorMockRecorder[MockCreator], r *mock_azure.MockResourceSpecGetterMockRecorder) {
gomock.InOrder(
r.ResourceName().Return(resourceName),
r.ResourceGroupName().Return(resourceGroupName),
Expand All @@ -79,7 +79,7 @@ func TestServiceCreateOrUpdateResource(t *testing.T) {
name: "operation in progress",
serviceName: serviceName,
expectedError: "operation type PUT on Azure resource mock-resourcegroup/mock-resource is not done. Object will be requeued after 15s",
expect: func(g *WithT, s *mock_asyncpoller.MockFutureScopeMockRecorder, c *mock_asyncpoller.MockCreatorMockRecorder[MockCreator], r *mock_azure.MockResourceSpecGetterMockRecorder) {
expect: func(g *WithT, s *mock_async.MockFutureScopeMockRecorder, c *mock_async.MockCreatorMockRecorder[MockCreator], r *mock_azure.MockResourceSpecGetterMockRecorder) {
gomock.InOrder(
r.ResourceName().Return(resourceName),
r.ResourceGroupName().Return(resourceGroupName),
Expand All @@ -93,7 +93,7 @@ func TestServiceCreateOrUpdateResource(t *testing.T) {
name: "get returns resource not found error",
serviceName: serviceName,
expectedError: "operation type PUT on Azure resource mock-resourcegroup/mock-resource is not done. Object will be requeued after 15s",
expect: func(g *WithT, s *mock_asyncpoller.MockFutureScopeMockRecorder, c *mock_asyncpoller.MockCreatorMockRecorder[MockCreator], r *mock_azure.MockResourceSpecGetterMockRecorder) {
expect: func(g *WithT, s *mock_async.MockFutureScopeMockRecorder, c *mock_async.MockCreatorMockRecorder[MockCreator], r *mock_azure.MockResourceSpecGetterMockRecorder) {
gomock.InOrder(
r.ResourceName().Return(resourceName),
r.ResourceGroupName().Return(resourceGroupName),
Expand All @@ -109,7 +109,7 @@ func TestServiceCreateOrUpdateResource(t *testing.T) {
name: "get returns unexpected error",
serviceName: serviceName,
expectedError: "failed to get existing resource mock-resourcegroup/mock-resource (service: mock-service): foo. Object will be requeued after 15s",
expect: func(g *WithT, s *mock_asyncpoller.MockFutureScopeMockRecorder, c *mock_asyncpoller.MockCreatorMockRecorder[MockCreator], r *mock_azure.MockResourceSpecGetterMockRecorder) {
expect: func(g *WithT, s *mock_async.MockFutureScopeMockRecorder, c *mock_async.MockCreatorMockRecorder[MockCreator], r *mock_azure.MockResourceSpecGetterMockRecorder) {
gomock.InOrder(
r.ResourceName().Return(resourceName),
r.ResourceGroupName().Return(resourceGroupName),
Expand All @@ -123,7 +123,7 @@ func TestServiceCreateOrUpdateResource(t *testing.T) {
serviceName: serviceName,
expectedError: "",
expectedResult: fakeResource,
expect: func(g *WithT, s *mock_asyncpoller.MockFutureScopeMockRecorder, c *mock_asyncpoller.MockCreatorMockRecorder[MockCreator], r *mock_azure.MockResourceSpecGetterMockRecorder) {
expect: func(g *WithT, s *mock_async.MockFutureScopeMockRecorder, c *mock_async.MockCreatorMockRecorder[MockCreator], r *mock_azure.MockResourceSpecGetterMockRecorder) {
gomock.InOrder(
r.ResourceName().Return(resourceName),
r.ResourceGroupName().Return(resourceGroupName),
Expand All @@ -138,7 +138,7 @@ func TestServiceCreateOrUpdateResource(t *testing.T) {
serviceName: serviceName,
expectedError: "failed to get desired parameters for resource mock-resourcegroup/mock-resource (service: mock-service): foo",
expectedResult: nil,
expect: func(g *WithT, s *mock_asyncpoller.MockFutureScopeMockRecorder, c *mock_asyncpoller.MockCreatorMockRecorder[MockCreator], r *mock_azure.MockResourceSpecGetterMockRecorder) {
expect: func(g *WithT, s *mock_async.MockFutureScopeMockRecorder, c *mock_async.MockCreatorMockRecorder[MockCreator], r *mock_azure.MockResourceSpecGetterMockRecorder) {
gomock.InOrder(
r.ResourceName().Return(resourceName),
r.ResourceGroupName().Return(resourceGroupName),
Expand All @@ -158,8 +158,8 @@ func TestServiceCreateOrUpdateResource(t *testing.T) {
t.Parallel()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
scopeMock := mock_asyncpoller.NewMockFutureScope(mockCtrl)
creatorMock := mock_asyncpoller.NewMockCreator[MockCreator](mockCtrl)
scopeMock := mock_async.NewMockFutureScope(mockCtrl)
creatorMock := mock_async.NewMockCreator[MockCreator](mockCtrl)
svc := New[MockCreator, MockDeleter](scopeMock, creatorMock, nil)
specMock := mock_azure.NewMockResourceSpecGetter(mockCtrl)

Expand Down Expand Up @@ -187,13 +187,13 @@ func TestServiceDeleteResource(t *testing.T) {
serviceName string
expectedError string
expectedResult interface{}
expect func(s *mock_asyncpoller.MockFutureScopeMockRecorder, d *mock_asyncpoller.MockDeleterMockRecorder[MockDeleter], r *mock_azure.MockResourceSpecGetterMockRecorder)
expect func(s *mock_async.MockFutureScopeMockRecorder, d *mock_async.MockDeleterMockRecorder[MockDeleter], r *mock_azure.MockResourceSpecGetterMockRecorder)
}{
{
name: "invalid future",
serviceName: serviceName,
expectedError: "could not decode future data",
expect: func(s *mock_asyncpoller.MockFutureScopeMockRecorder, d *mock_asyncpoller.MockDeleterMockRecorder[MockDeleter], r *mock_azure.MockResourceSpecGetterMockRecorder) {
expect: func(s *mock_async.MockFutureScopeMockRecorder, d *mock_async.MockDeleterMockRecorder[MockDeleter], r *mock_azure.MockResourceSpecGetterMockRecorder) {
gomock.InOrder(
r.ResourceName().Return(resourceName),
r.ResourceGroupName().Return(resourceGroupName),
Expand All @@ -206,7 +206,7 @@ func TestServiceDeleteResource(t *testing.T) {
name: "valid future",
serviceName: serviceName,
expectedError: "",
expect: func(s *mock_asyncpoller.MockFutureScopeMockRecorder, d *mock_asyncpoller.MockDeleterMockRecorder[MockDeleter], r *mock_azure.MockResourceSpecGetterMockRecorder) {
expect: func(s *mock_async.MockFutureScopeMockRecorder, d *mock_async.MockDeleterMockRecorder[MockDeleter], r *mock_azure.MockResourceSpecGetterMockRecorder) {
gomock.InOrder(
r.ResourceName().Return(resourceName),
r.ResourceGroupName().Return(resourceGroupName),
Expand All @@ -226,8 +226,8 @@ func TestServiceDeleteResource(t *testing.T) {
t.Parallel()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
scopeMock := mock_asyncpoller.NewMockFutureScope(mockCtrl)
deleterMock := mock_asyncpoller.NewMockDeleter[MockDeleter](mockCtrl)
scopeMock := mock_async.NewMockFutureScope(mockCtrl)
deleterMock := mock_async.NewMockDeleter[MockDeleter](mockCtrl)
svc := New[MockCreator, MockDeleter](scopeMock, nil, deleterMock)
specMock := mock_azure.NewMockResourceSpecGetter(mockCtrl)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package asyncpoller
package async

import (
"context"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ limitations under the License.

// Run go generate to regenerate this mock.
//
//go:generate ../../../../hack/tools/bin/mockgen -destination asyncpoller_mock.go -package mock_asyncpoller -source ../interfaces.go FutureHandler
//go:generate /usr/bin/env bash -c "cat ../../../../hack/boilerplate/boilerplate.generatego.txt asyncpoller_mock.go > _asyncpoller_mock.go && mv _asyncpoller_mock.go asyncpoller_mock.go"
package mock_asyncpoller
//go:generate ../../../../hack/tools/bin/mockgen -destination async_mock.go -package mock_async -source ../interfaces.go FutureHandler
//go:generate /usr/bin/env bash -c "cat ../../../../hack/boilerplate/boilerplate.generatego.txt async_mock.go > _async_mock.go && mv _async_mock.go async_mock.go"
package mock_async
Loading

0 comments on commit e5e60ff

Please sign in to comment.