Skip to content

Commit

Permalink
return struct instead of interface
Browse files Browse the repository at this point in the history
  • Loading branch information
bitoku committed Nov 25, 2024
1 parent 3bdec53 commit bb699bb
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/Azure/ARO-RP/pkg/util/subnet"
)

func NewFeature(flowLogsClient armnetwork.FlowLogsClient, kubeSubnets subnet.KubeManager, subnets armnetwork.SubnetsClient, location string) *nsgFlowLogsFeature {
func NewFeature(flowLogsClient armnetwork.FlowLogsClientInterface, kubeSubnets subnet.KubeManager, subnets armnetwork.SubnetsClient, location string) *nsgFlowLogsFeature {
return &nsgFlowLogsFeature{
kubeSubnets: kubeSubnets,
flowLogsClient: flowLogsClient,
Expand All @@ -29,7 +29,7 @@ func NewFeature(flowLogsClient armnetwork.FlowLogsClient, kubeSubnets subnet.Kub
type nsgFlowLogsFeature struct {
kubeSubnets subnet.KubeManager
subnets armnetwork.SubnetsClient
flowLogsClient armnetwork.FlowLogsClient
flowLogsClient armnetwork.FlowLogsClientInterface
location string
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestReconcileManager(t *testing.T) {
name string
subnetMock func(*mock_armnetwork.MockSubnetsClient, *mock_subnet.MockKubeManager)
instance func(*aropreviewv1alpha1.PreviewFeature)
flowLogClientMock func(*mock_armnetwork.MockFlowLogsClient)
flowLogClientMock func(*mock_armnetwork.MockFlowLogsClientInterface)
wantErr string
}{
{
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestReconcileManager(t *testing.T) {
},
}, nil)
},
flowLogClientMock: func(client *mock_armnetwork.MockFlowLogsClient) {
flowLogClientMock: func(client *mock_armnetwork.MockFlowLogsClientInterface) {
flowLogMaster := getValidFlowLogFeature()
flowLogMaster.Properties.TargetResourceID = &subnetNameMasterNSGID

Expand Down Expand Up @@ -224,7 +224,7 @@ func TestReconcileManager(t *testing.T) {
},
}, nil)
},
flowLogClientMock: func(client *mock_armnetwork.MockFlowLogsClient) {
flowLogClientMock: func(client *mock_armnetwork.MockFlowLogsClientInterface) {
client.EXPECT().DeleteAndWait(gomock.Any(), networkWatcherResourceGroupName, networkWatcherName, subnetNameMasterNSGName, nil)
client.EXPECT().DeleteAndWait(gomock.Any(), networkWatcherResourceGroupName, networkWatcherName, subnetNameWorkerNSGName, nil)
},
Expand All @@ -250,7 +250,7 @@ func TestReconcileManager(t *testing.T) {
tt.instance(instance)
}

flowLogsClient := mock_armnetwork.NewMockFlowLogsClient(controller)
flowLogsClient := mock_armnetwork.NewMockFlowLogsClientInterface(controller)
if tt.flowLogClientMock != nil {
tt.flowLogClientMock(flowLogsClient)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/util/azureclient/azuresdk/armnetwork/flowlogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ import (
"github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/azcore"
)

// FlowLogsClient is a minimal interface for azure FlowLogsClient
type FlowLogsClient interface {
// FlowLogsClientInterface is a minimal interface for azure FlowLogsClientInterface
type FlowLogsClientInterface interface {
Get(ctx context.Context, resourceGroupName string, networkWatcherName string, flowLogName string, options *armnetwork.FlowLogsClientGetOptions) (result armnetwork.FlowLogsClientGetResponse, err error)

FlowLogsClientAddons
}

type flowLogsClient struct {
type FlowLogsClient struct {
*armnetwork.FlowLogsClient
}

func NewFlowLogsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (FlowLogsClient, error) {
func NewFlowLogsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*FlowLogsClient, error) {
client, err := armnetwork.NewFlowLogsClient(subscriptionID, credential, options)
return &flowLogsClient{client}, err
return &FlowLogsClient{client}, err
}
4 changes: 2 additions & 2 deletions pkg/util/azureclient/azuresdk/armnetwork/flowlogs_addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type FlowLogsClientAddons interface {
DeleteAndWait(ctx context.Context, resourceGroupName string, networkWatcherName string, flowLogName string, options *armnetwork.FlowLogsClientBeginDeleteOptions) error
}

func (c *flowLogsClient) CreateOrUpdateAndWait(ctx context.Context, resourceGroupName string, networkWatcherName string, flowLogName string, parameters armnetwork.FlowLog, options *armnetwork.FlowLogsClientBeginCreateOrUpdateOptions) error {
func (c *FlowLogsClient) CreateOrUpdateAndWait(ctx context.Context, resourceGroupName string, networkWatcherName string, flowLogName string, parameters armnetwork.FlowLog, options *armnetwork.FlowLogsClientBeginCreateOrUpdateOptions) error {
poller, err := c.FlowLogsClient.BeginCreateOrUpdate(ctx, resourceGroupName, networkWatcherName, flowLogName, parameters, options)
if err != nil {
return err
Expand All @@ -24,7 +24,7 @@ func (c *flowLogsClient) CreateOrUpdateAndWait(ctx context.Context, resourceGrou
return err
}

func (c *flowLogsClient) DeleteAndWait(ctx context.Context, resourceGroupName string, networkWatcherName string, flowLogName string, options *armnetwork.FlowLogsClientBeginDeleteOptions) error {
func (c *FlowLogsClient) DeleteAndWait(ctx context.Context, resourceGroupName string, networkWatcherName string, flowLogName string, options *armnetwork.FlowLogsClientBeginDeleteOptions) error {
poller, err := c.FlowLogsClient.BeginDelete(ctx, resourceGroupName, networkWatcherName, flowLogName, options)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/azureclient/azuresdk/armnetwork/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ package armnetwork
// Licensed under the Apache License 2.0.

//go:generate rm -rf ../../../../util/mocks/$GOPACKAGE
//go:generate mockgen -destination=../../../../util/mocks/azureclient/azuresdk/$GOPACKAGE/$GOPACKAGE.go github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/$GOPACKAGE FlowLogsClient,InterfacesClient,LoadBalancersClient,LoadBalancerBackendAddressPoolsClient,PrivateEndpointsClient,PrivateLinkServicesClient,PublicIPAddressesClient,RouteTablesClient,SecurityGroupsClient,SubnetsClient,VirtualNetworksClient
//go:generate mockgen -destination=../../../../util/mocks/azureclient/azuresdk/$GOPACKAGE/$GOPACKAGE.go github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/$GOPACKAGE FlowLogsClientInterface,InterfacesClient,LoadBalancersClient,LoadBalancerBackendAddressPoolsClient,PrivateEndpointsClient,PrivateLinkServicesClient,PublicIPAddressesClient,RouteTablesClient,SecurityGroupsClient,SubnetsClient,VirtualNetworksClient
//go:generate goimports -local=github.com/Azure/ARO-RP -e -w ../../../../util/mocks/azureclient/azuresdk/$GOPACKAGE/$GOPACKAGE.go
44 changes: 22 additions & 22 deletions pkg/util/mocks/azureclient/azuresdk/armnetwork/armnetwork.go

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

0 comments on commit bb699bb

Please sign in to comment.