Skip to content

Commit

Permalink
Fixes linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
wbreza committed Aug 27, 2024
1 parent f2a477c commit 5da0f28
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 175 deletions.
8 changes: 4 additions & 4 deletions cli/azd/pkg/project/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ services:
},
})
resourceService := azapi.NewResourceService(mockContext.SubscriptionCredentialProvider, mockContext.ArmClientOptions)
deploymentService := mockazcli.NewDeploymentsServiceFromMockContext(mockContext)
deploymentService := mockazcli.NewStandardDeploymentsFromMockContext(mockContext)

env := environment.NewWithValues("envA", map[string]string{
environment.SubscriptionIdEnvVarName: "SUBSCRIPTION_ID",
Expand Down Expand Up @@ -95,7 +95,7 @@ services:
},
)
resourceService := azapi.NewResourceService(mockContext.SubscriptionCredentialProvider, mockContext.ArmClientOptions)
deploymentService := mockazcli.NewDeploymentsServiceFromMockContext(mockContext)
deploymentService := mockazcli.NewStandardDeploymentsFromMockContext(mockContext)

env := environment.NewWithValues("envA", map[string]string{
environment.SubscriptionIdEnvVarName: "SUBSCRIPTION_ID",
Expand Down Expand Up @@ -151,7 +151,7 @@ services:
},
})
resourceService := azapi.NewResourceService(mockContext.SubscriptionCredentialProvider, mockContext.ArmClientOptions)
deploymentService := mockazcli.NewDeploymentsServiceFromMockContext(mockContext)
deploymentService := mockazcli.NewStandardDeploymentsFromMockContext(mockContext)

env := environment.NewWithValues("envA", map[string]string{
environment.SubscriptionIdEnvVarName: "SUBSCRIPTION_ID",
Expand Down Expand Up @@ -211,7 +211,7 @@ services:
},
})
resourceService := azapi.NewResourceService(mockContext.SubscriptionCredentialProvider, mockContext.ArmClientOptions)
deploymentService := mockazcli.NewDeploymentsServiceFromMockContext(mockContext)
deploymentService := mockazcli.NewStandardDeploymentsFromMockContext(mockContext)

env := environment.NewWithValues("envA", map[string]string{
environment.ResourceGroupEnvVarName: expectedResourceGroupName,
Expand Down
171 changes: 2 additions & 169 deletions cli/azd/pkg/project/resource_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import (

"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
"github.com/azure/azure-dev/cli/azd/pkg/async"
"github.com/azure/azure-dev/cli/azd/pkg/azapi"
"github.com/azure/azure-dev/cli/azd/pkg/azure"
"github.com/azure/azure-dev/cli/azd/pkg/environment"
"github.com/azure/azure-dev/cli/azd/pkg/osutil"
"github.com/azure/azure-dev/cli/azd/test/mocks"
"github.com/stretchr/testify/mock"
"github.com/azure/azure-dev/cli/azd/test/mocks/mockazcli"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -99,7 +97,7 @@ func Test_ResourceManager_GetTargetResource(t *testing.T) {
mockContext.SubscriptionCredentialProvider,
mockContext.ArmClientOptions,
)
deploymentService := &mockDeploymentService{}
deploymentService := mockazcli.NewStandardDeploymentsFromMockContext(mockContext)

if tt.init != nil {
tt.init(mockContext)
Expand Down Expand Up @@ -130,171 +128,6 @@ func Test_ResourceManager_GetTargetResource(t *testing.T) {
}
}

type mockDeploymentService struct {
mock.Mock
}

// GenerateDeploymentName implements azapi.DeploymentService.
func (m *mockDeploymentService) GenerateDeploymentName(baseName string) string {
args := m.Called(baseName)
return args.Get(0).(string)
}

// ListResourceGroupDeploymentResources implements azapi.DeploymentService.
func (m *mockDeploymentService) ListResourceGroupDeploymentResources(
ctx context.Context,
subscriptionId string,
resourceGroupName string,
deploymentName string,
) ([]*armresources.ResourceReference, error) {
args := m.Called(ctx, subscriptionId, resourceGroupName, deploymentName)
return args.Get(0).([]*armresources.ResourceReference), args.Error(1)
}

// ListSubscriptionDeploymentResources implements azapi.DeploymentService.
func (m *mockDeploymentService) ListSubscriptionDeploymentResources(
ctx context.Context,
subscriptionId string,
deploymentName string,
) ([]*armresources.ResourceReference, error) {
args := m.Called(ctx, subscriptionId, deploymentName)
return args.Get(0).([]*armresources.ResourceReference), args.Error(1)
}

func (m *mockDeploymentService) ListSubscriptionDeployments(
ctx context.Context,
subscriptionId string,
) ([]*azapi.ResourceDeployment, error) {
args := m.Called(ctx, subscriptionId)
return args.Get(0).([]*azapi.ResourceDeployment), args.Error(1)
}

func (m *mockDeploymentService) GetSubscriptionDeployment(
ctx context.Context,
subscriptionId string,
deploymentName string,
) (*azapi.ResourceDeployment, error) {
args := m.Called(ctx, subscriptionId, deploymentName)
return args.Get(0).(*azapi.ResourceDeployment), args.Error(1)
}

func (m *mockDeploymentService) ListResourceGroupDeployments(
ctx context.Context,
subscriptionId string,
resourceGroupName string,
) ([]*azapi.ResourceDeployment, error) {
args := m.Called(ctx, subscriptionId, resourceGroupName)
return args.Get(0).([]*azapi.ResourceDeployment), args.Error(1)
}

func (m *mockDeploymentService) GetResourceGroupDeployment(
ctx context.Context,
subscriptionId string,
resourceGroupName string,
deploymentName string,
) (*azapi.ResourceDeployment, error) {
args := m.Called(ctx, subscriptionId, resourceGroupName, deploymentName)
return args.Get(0).(*azapi.ResourceDeployment), args.Error(1)
}

func (m *mockDeploymentService) DeployToSubscription(
ctx context.Context,
subscriptionId string,
location string,
deploymentName string,
armTemplate azure.RawArmTemplate,
parameters azure.ArmParameters,
tags map[string]*string,
) (*azapi.ResourceDeployment, error) {
args := m.Called(ctx, subscriptionId, location, deploymentName, armTemplate, parameters, tags)
return args.Get(0).(*azapi.ResourceDeployment), args.Error(1)
}

func (m *mockDeploymentService) DeployToResourceGroup(
ctx context.Context,
subscriptionId string,
resourceGroup string,
deploymentName string,
armTemplate azure.RawArmTemplate,
parameters azure.ArmParameters,
tags map[string]*string,
) (*azapi.ResourceDeployment, error) {
args := m.Called(ctx, subscriptionId, resourceGroup, deploymentName, armTemplate, parameters, tags)
return args.Get(0).(*azapi.ResourceDeployment), args.Error(1)
}

func (m *mockDeploymentService) WhatIfDeployToSubscription(
ctx context.Context,
subscriptionId string,
location string,
deploymentName string,
armTemplate azure.RawArmTemplate,
parameters azure.ArmParameters,
) (*armresources.WhatIfOperationResult, error) {
args := m.Called(ctx, subscriptionId, location, deploymentName, armTemplate, parameters)
return args.Get(0).(*armresources.WhatIfOperationResult), args.Error(1)
}

func (m *mockDeploymentService) WhatIfDeployToResourceGroup(
ctx context.Context,
subscriptionId string,
resourceGroup string,
deploymentName string,
armTemplate azure.RawArmTemplate,
parameters azure.ArmParameters,
) (*armresources.WhatIfOperationResult, error) {
args := m.Called(ctx, subscriptionId, resourceGroup, deploymentName, armTemplate, parameters)
return args.Get(0).(*armresources.WhatIfOperationResult), args.Error(1)
}

func (m *mockDeploymentService) DeleteSubscriptionDeployment(
ctx context.Context,
subscriptionId string,
deploymentName string,
progress *async.Progress[azapi.DeleteDeploymentProgress],
) error {
args := m.Called(ctx, subscriptionId, deploymentName, progress)
return args.Error(0)
}
func (m *mockDeploymentService) DeleteResourceGroupDeployment(
ctx context.Context,
subscriptionId string,
resourceGroupName string,
deploymentName string,
progress *async.Progress[azapi.DeleteDeploymentProgress],
) error {
args := m.Called(ctx, subscriptionId, resourceGroupName, deploymentName, progress)
return args.Error(0)
}

func (m *mockDeploymentService) CalculateTemplateHash(
ctx context.Context,
subscriptionId string,
template azure.RawArmTemplate,
) (string, error) {
args := m.Called(ctx, subscriptionId, template)
return args.Get(0).(string), args.Error(1)
}

func (m *mockDeploymentService) ListSubscriptionDeploymentOperations(
ctx context.Context,
subscriptionId string,
deploymentName string,
) ([]*armresources.DeploymentOperation, error) {
args := m.Called(ctx, subscriptionId, deploymentName)
return args.Get(0).([]*armresources.DeploymentOperation), args.Error(1)
}

func (m *mockDeploymentService) ListResourceGroupDeploymentOperations(
ctx context.Context,
subscriptionId string,
resourceGroupName string,
deploymentName string,
) ([]*armresources.DeploymentOperation, error) {
args := m.Called(ctx, subscriptionId, resourceGroupName, deploymentName)
return args.Get(0).([]*armresources.DeploymentOperation), args.Error(1)
}

func setupGetResourceGroupMock(mockContext *mocks.MockContext, resourceGroup *armresources.ResourceGroup) {
mockContext.HttpClient.When(func(request *http.Request) bool {
return strings.HasSuffix(request.URL.Path, "/resourcegroups") && strings.Contains(request.URL.RawQuery, "filter=")
Expand Down
2 changes: 1 addition & 1 deletion cli/azd/pkg/project/service_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func createServiceManager(
env *environment.Environment,
operationCache ServiceOperationCache,
) ServiceManager {
deploymentService := mockazcli.NewDeploymentsServiceFromMockContext(mockContext)
deploymentService := mockazcli.NewStandardDeploymentsFromMockContext(mockContext)
resourceService := azapi.NewResourceService(mockContext.SubscriptionCredentialProvider, mockContext.ArmClientOptions)
resourceManager := NewResourceManager(env, deploymentService, resourceService)

Expand Down
2 changes: 1 addition & 1 deletion cli/azd/pkg/project/service_target_containerapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func createContainerAppServiceTarget(
mockContext.Console,
cloud.AzurePublic(),
)
deploymentService := mockazcli.NewDeploymentsServiceFromMockContext(mockContext)
deploymentService := mockazcli.NewStandardDeploymentsFromMockContext(mockContext)
resourceService := azapi.NewResourceService(credentialProvider, mockContext.ArmClientOptions)
resourceManager := NewResourceManager(env, deploymentService, resourceService)

Expand Down

0 comments on commit 5da0f28

Please sign in to comment.