From 956d28691253e028a342363e442a849f9f62e1ef Mon Sep 17 00:00:00 2001 From: Dariusz Dwornikowski Date: Tue, 23 Apr 2019 17:26:10 +0200 Subject: [PATCH] Mocks and basic tests --- Gopkg.lock | 40 ++++- README.md | 4 +- cmd/cli/commands/check.go | 1 - internal/azure/backup.go | 23 +-- internal/azure/functions.go | 99 ------------ internal/azure/scanner.go | 2 - internal/azure/tagger.go | 135 +++++++++++++--- mocks/ClientAPI.go | 307 ++++++++++++++++++++++++++++++++++++ 8 files changed, 470 insertions(+), 141 deletions(-) delete mode 100644 internal/azure/functions.go create mode 100644 mocks/ClientAPI.go diff --git a/Gopkg.lock b/Gopkg.lock index 0985b6e..0321a34 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -10,10 +10,11 @@ version = "v0.2.0" [[projects]] - digest = "1:8f6e0003b21d364e7b51d3789801e2ba515a0e573d6a820630925f1e93cdea29" + digest = "1:d74599516e792dcfc36ee8354f3222193f6116a4db4f66fc2134ef05c6f0f158" name = "github.com/Azure/azure-sdk-for-go" packages = [ "services/resources/mgmt/2018-02-01/resources", + "services/resources/mgmt/2018-02-01/resources/resourcesapi", "version", ] pruneopts = "UT" @@ -52,6 +53,14 @@ revision = "7f2434bc10da710debe5c4315ed6d4df454b4024" version = "v0.1.0" +[[projects]] + digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec" + name = "github.com/davecgh/go-spew" + packages = ["spew"] + pruneopts = "UT" + revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73" + version = "v1.1.1" + [[projects]] digest = "1:76dc72490af7174349349838f2fe118996381b31ea83243812a97e5a0fd5ed55" name = "github.com/dgrijalva/jwt-go" @@ -123,6 +132,14 @@ revision = "ba968bfe8b2f7e042a574c888954fccecfa385b4" version = "v0.8.1" +[[projects]] + digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe" + name = "github.com/pmezard/go-difflib" + packages = ["difflib"] + pruneopts = "UT" + revision = "792786c7400a136282c1664665ae0a8db921c6c2" + version = "v1.0.0" + [[projects]] digest = "1:87c2e02fb01c27060ccc5ba7c5a407cc91147726f8f40b70cceeedbc52b1f3a8" name = "github.com/sirupsen/logrus" @@ -147,6 +164,25 @@ revision = "298182f68c66c05229eb03ac171abe6e309ee79a" version = "v1.0.3" +[[projects]] + digest = "1:ac83cf90d08b63ad5f7e020ef480d319ae890c208f8524622a2f3136e2686b02" + name = "github.com/stretchr/objx" + packages = ["."] + pruneopts = "UT" + revision = "477a77ecc69700c7cdeb1fa9e129548e1c1c393c" + version = "v0.1.1" + +[[projects]] + digest = "1:0bcc464dabcfad5393daf87c3f8142911d0f6c52569b837e91a1c15e890265f3" + name = "github.com/stretchr/testify" + packages = [ + "assert", + "mock", + ] + pruneopts = "UT" + revision = "ffdc059bfe9ce6a4e144ba849dbedead332c6053" + version = "v1.3.0" + [[projects]] digest = "1:2ae8314c44cd413cfdb5b1df082b350116dd8d2fff973e62c01b285b7affd89e" name = "go.opencensus.io" @@ -310,6 +346,7 @@ analyzer-version = 1 input-imports = [ "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-02-01/resources", + "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-02-01/resources/resourcesapi", "github.com/Azure/go-autorest/autorest", "github.com/Azure/go-autorest/autorest/azure", "github.com/Azure/go-autorest/autorest/azure/auth", @@ -317,6 +354,7 @@ "github.com/pkg/errors", "github.com/sirupsen/logrus", "github.com/spf13/cobra", + "github.com/stretchr/testify/mock", ] solver-name = "gps-cdcl" solver-version = 1 diff --git a/README.md b/README.md index 3580e18..e043e96 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,6 @@ Commands: * `retagrg` - Takes tags form a given resource group (`--rg`) and applies them to all of the resources in the resource group. If any existing tags are already there, the new ones with be appended. Adding `--cleantags` will clean ALL the tags on resources before adding new ones. - ## Changelog 0.4.7 @@ -163,5 +162,4 @@ Commands: Dariusz Dwornikowski, -Nordcloud PAT team (Hold my 🍺, not hold my 🐴🐴) - +Nordcloud PAT team (Hold my 🍺, not hold my 🐴🐴) \ No newline at end of file diff --git a/cmd/cli/commands/check.go b/cmd/cli/commands/check.go index c161473..ece1dd8 100644 --- a/cmd/cli/commands/check.go +++ b/cmd/cli/commands/check.go @@ -52,5 +52,4 @@ var checkCommand = &cobra.Command{ } return nil - }, } diff --git a/internal/azure/backup.go b/internal/azure/backup.go index 0619063..9ca409f 100644 --- a/internal/azure/backup.go +++ b/internal/azure/backup.go @@ -10,6 +10,7 @@ import ( "bitbucket.org/nordcloud/tagmanager/internal/azure/session" "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-02-01/resources" + "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-02-01/resources/resourcesapi" "github.com/pkg/errors" ) @@ -18,6 +19,17 @@ type BackupEntry struct { Tags map[string]*string `json:"tags"` } +type Restorer interface { + Restore() error +} + +type TagRestorer struct { + Session *session.AzureSession + ResourcesClient resourcesapi.ClientAPI + ReplaceTags bool + Backup []BackupEntry +} + //NewBackupFromMatched make a file backup from the matching resources func NewBackupFromMatched(matched map[string]Matched, directory string) string { var backup []BackupEntry @@ -45,17 +57,6 @@ func NewBackupFromMatched(matched map[string]Matched, directory string) string { return tmpfile.Name() } -type Restorer interface { - Restore() error -} - -type TagRestorer struct { - Session *session.AzureSession - ResourcesClient *resources.Client - ReplaceTags bool - Backup []BackupEntry -} - func (t TagRestorer) Restore() error { for _, backupEntry := range t.Backup { fmt.Printf("Restoring tags for [%s]\n", backupEntry.ID) diff --git a/internal/azure/functions.go b/internal/azure/functions.go deleted file mode 100644 index be90ec7..0000000 --- a/internal/azure/functions.go +++ /dev/null @@ -1,99 +0,0 @@ -package azure - -import ( - "context" - - "bitbucket.org/nordcloud/tagmanager/internal/azure/rules" - "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-02-01/resources" - "github.com/pkg/errors" - log "github.com/sirupsen/logrus" -) - -func (t Tagger) deleteAllTags(id string) error { - - _, err := t.ResourcesClient.GetByID(context.Background(), id) - if err != nil { - return errors.Wrap(err, "cannot get resource by id") - } - - genericResource := resources.GenericResource{ - Tags: make(map[string]*string), - } - - _, err = t.ResourcesClient.UpdateByID(context.Background(), id, genericResource) - if err != nil { - return errors.Wrap(err, "cannot update resource by id") - } - - return err -} - -func (t Tagger) deleteTag(id, tag string) error { - - r, err := t.ResourcesClient.GetByID(context.Background(), id) - if err != nil { - return errors.Wrap(err, "cannot get resource by id") - } - - if _, ok := r.Tags[tag]; !ok { - return nil - } - - delete(r.Tags, tag) - genericResource := resources.GenericResource{ - Tags: r.Tags, - } - - _, err = t.ResourcesClient.UpdateByID(context.Background(), id, genericResource) - if err != nil { - return errors.Wrap(err, "cannot update resource by id") - } - - return err -} - -func (t Tagger) createOrUpdateTag(id, tag, value string) error { - - r, err := t.ResourcesClient.GetByID(context.Background(), id) - if err != nil { - return errors.Wrap(err, "cannot get resource by id") - } - - if _, ok := r.Tags[tag]; ok { - return nil - } - - if r.Tags == nil { - r.Tags = make(map[string]*string) - } - - r.Tags[tag] = &value - genericResource := resources.GenericResource{ - Tags: r.Tags, - } - - _, err = t.ResourcesClient.UpdateByID(context.Background(), id, genericResource) - if err != nil { - return errors.Wrap(err, "cannot update resource by id") - } - - return err -} - -func (t *Tagger) Execute(data *Resource, p rules.ActionItem) error { - if val, ok := t.actionMap[p.GetType()]; ok { - return val(p, data) - } - - log.Warnf("Unknown action type %s", p.GetType()) - return nil -} - -func (t *Tagger) Eval(data *Resource, p rules.ConditionItem) bool { - if val, ok := t.condMap[p.GetType()]; ok { - return val(p, data) - } - - log.Warnf("Unknown condition type %s", p.GetType()) - return false -} diff --git a/internal/azure/scanner.go b/internal/azure/scanner.go index 33c85f9..68ea765 100644 --- a/internal/azure/scanner.go +++ b/internal/azure/scanner.go @@ -123,7 +123,6 @@ func (r ResourceGroupScanner) GetResourcesByResourceGroup(rg string) ([]Resource } resource := list.Value() - tab = append(tab, Resource{ Platform: "azure", ID: *resource.ID, @@ -132,6 +131,5 @@ func (r ResourceGroupScanner) GetResourcesByResourceGroup(rg string) ([]Resource Tags: resource.Tags, }) } - return tab, nil } diff --git a/internal/azure/tagger.go b/internal/azure/tagger.go index cdff365..5641c8c 100644 --- a/internal/azure/tagger.go +++ b/internal/azure/tagger.go @@ -1,13 +1,33 @@ package azure import ( + "context" + "fmt" + "bitbucket.org/nordcloud/tagmanager/internal/azure/rules" "bitbucket.org/nordcloud/tagmanager/internal/azure/session" "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-02-01/resources" + "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-02-01/resources/resourcesapi" "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) +type Tagger struct { + Session *session.AzureSession + Matched map[string]Matched + Rules rules.TagRules + condMap condFuncMap + actionMap actionFuncMap + dryRun bool + ResourcesClient resourcesapi.ClientAPI +} + +// Matched stores +type Matched struct { + Resource Resource + TagRules []rules.Rule +} + //ActionExecution stores information about execution of actions of a rule type ActionExecution struct { ResourceID string @@ -33,22 +53,6 @@ func NewTagger(ruleDef rules.TagRules, session *session.AzureSession) *Tagger { return &tagger } -// Matched stores -type Matched struct { - Resource Resource - TagRules []rules.Rule -} - -type Tagger struct { - Session *session.AzureSession - Matched map[string]Matched - Rules rules.TagRules - condMap condFuncMap - actionMap actionFuncMap - dryRun bool - ResourcesClient *resources.Client -} - func (t *Tagger) DryRun() { t.dryRun = true } @@ -176,10 +180,9 @@ func (t *Tagger) InitCondMap() { } } -func (t Tagger) ExecuteActions() (error, []ActionExecution) { +func (t *Tagger) ExecuteActions() ([]ActionExecution, error) { ael := make([]ActionExecution, 0) for resID, matched := range t.Matched { - for _, rule := range matched.TagRules { ae := ActionExecution{ ResourceID: resID, @@ -187,27 +190,27 @@ func (t Tagger) ExecuteActions() (error, []ActionExecution) { Actions: rule.Actions, } for _, action := range rule.Actions { - if t.dryRun == true { - } else { + if t.dryRun != true { resource := Resource{ID: resID} err := t.Execute(&resource, action) if err != nil { - log.Errorf("Can't execute action [%s] on [%s]\n", action.GetType(), resource.ID, err) + msg := fmt.Sprintf("ExecuteActions(): Can't execute action [%s] on [%s], [%s]\n", action.GetType(), resource.ID, err) + return []ActionExecution{}, errors.New(msg) } } } ael = append(ael, ae) } } - return nil, ael + return ael, nil } // EvaluateRules iterates over all rules and resources and checks which conditions are true. -func (t Tagger) EvaluateRules(resources []Resource) error { +func (t Tagger) EvaluateRules(resources []Resource) { var evaled bool + for _, resource := range resources { evaled = true - log.Debugf("🔍 Checking resource: %s (%s) \n", *resource.Name, resource.ID) for _, y := range t.Rules.Rules { for _, cond := range y.Conditions { evaled = t.Eval(&resource, cond) @@ -227,6 +230,90 @@ func (t Tagger) EvaluateRules(resources []Resource) error { } } } +} + +func (t Tagger) deleteAllTags(id string) error { + genericResource := resources.GenericResource{ + Tags: make(map[string]*string), + } + _, err := t.ResourcesClient.UpdateByID(context.Background(), id, genericResource) + if err != nil { + return errors.Wrap(err, "cannot update resource by id") + } + + return err +} + +func (t Tagger) deleteTag(id, tag string) error { + + r, err := t.ResourcesClient.GetByID(context.Background(), id) + if err != nil { + return errors.Wrap(err, "cannot get resource by id") + } + + if _, ok := r.Tags[tag]; !ok { + return nil + } + + delete(r.Tags, tag) + genericResource := resources.GenericResource{ + Tags: r.Tags, + } + + _, err = t.ResourcesClient.UpdateByID(context.Background(), id, genericResource) + if err != nil { + return errors.Wrap(err, "cannot update resource by id") + } + + return err +} + +func (t Tagger) createOrUpdateTag(id, tag, value string) error { + + r, err := t.ResourcesClient.GetByID(context.Background(), id) + if err != nil { + return errors.Wrap(err, "cannot get resource by id") + } + + if _, ok := r.Tags[tag]; ok { + return nil + } + + if r.Tags == nil { + r.Tags = make(map[string]*string) + } + + r.Tags[tag] = &value + genericResource := resources.GenericResource{ + Tags: r.Tags, + } + + _, err = t.ResourcesClient.UpdateByID(context.Background(), id, genericResource) + if err != nil { + return errors.Wrap(err, "cannot update resource by id") + } + + return err +} + +func (t *Tagger) Execute(data *Resource, p rules.ActionItem) error { + if val, ok := t.actionMap[p.GetType()]; ok { + err := val(p, data) + if err != nil { + msg := fmt.Sprintf("Execute(action=%q) returned error %q", p.GetType(), err) + return errors.New(msg) + } + return nil + } + log.Warnf("Unknown action type %s - ignoring", p.GetType()) return nil } + +func (t *Tagger) Eval(data *Resource, p rules.ConditionItem) bool { + if val, ok := t.condMap[p.GetType()]; ok { + return val(p, data) + } + log.Warnf("Unknown condition type %s - ignoring", p.GetType()) + return false +} diff --git a/mocks/ClientAPI.go b/mocks/ClientAPI.go new file mode 100644 index 0000000..a0875d7 --- /dev/null +++ b/mocks/ClientAPI.go @@ -0,0 +1,307 @@ +// Code generated by mockery v1.0.0. DO NOT EDIT. + +package mocks + +import autorest "github.com/Azure/go-autorest/autorest" +import context "context" +import mock "github.com/stretchr/testify/mock" +import resources "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-02-01/resources" + +// ClientAPI is an autogenerated mock type for the ClientAPI type +type ClientAPI struct { + mock.Mock +} + +// CheckExistence provides a mock function with given fields: ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName +func (_m *ClientAPI) CheckExistence(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string) (autorest.Response, error) { + ret := _m.Called(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName) + + var r0 autorest.Response + if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string, string) autorest.Response); ok { + r0 = rf(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName) + } else { + r0 = ret.Get(0).(autorest.Response) + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string, string, string, string, string) error); ok { + r1 = rf(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CheckExistenceByID provides a mock function with given fields: ctx, resourceID +func (_m *ClientAPI) CheckExistenceByID(ctx context.Context, resourceID string) (autorest.Response, error) { + ret := _m.Called(ctx, resourceID) + + var r0 autorest.Response + if rf, ok := ret.Get(0).(func(context.Context, string) autorest.Response); ok { + r0 = rf(ctx, resourceID) + } else { + r0 = ret.Get(0).(autorest.Response) + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, resourceID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CreateOrUpdate provides a mock function with given fields: ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, parameters +func (_m *ClientAPI) CreateOrUpdate(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, parameters resources.GenericResource) (resources.CreateOrUpdateFuture, error) { + ret := _m.Called(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, parameters) + + var r0 resources.CreateOrUpdateFuture + if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string, string, resources.GenericResource) resources.CreateOrUpdateFuture); ok { + r0 = rf(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, parameters) + } else { + r0 = ret.Get(0).(resources.CreateOrUpdateFuture) + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string, string, string, string, string, resources.GenericResource) error); ok { + r1 = rf(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, parameters) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CreateOrUpdateByID provides a mock function with given fields: ctx, resourceID, parameters +func (_m *ClientAPI) CreateOrUpdateByID(ctx context.Context, resourceID string, parameters resources.GenericResource) (resources.CreateOrUpdateByIDFuture, error) { + ret := _m.Called(ctx, resourceID, parameters) + + var r0 resources.CreateOrUpdateByIDFuture + if rf, ok := ret.Get(0).(func(context.Context, string, resources.GenericResource) resources.CreateOrUpdateByIDFuture); ok { + r0 = rf(ctx, resourceID, parameters) + } else { + r0 = ret.Get(0).(resources.CreateOrUpdateByIDFuture) + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string, resources.GenericResource) error); ok { + r1 = rf(ctx, resourceID, parameters) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Delete provides a mock function with given fields: ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName +func (_m *ClientAPI) Delete(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string) (resources.DeleteFuture, error) { + ret := _m.Called(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName) + + var r0 resources.DeleteFuture + if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string, string) resources.DeleteFuture); ok { + r0 = rf(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName) + } else { + r0 = ret.Get(0).(resources.DeleteFuture) + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string, string, string, string, string) error); ok { + r1 = rf(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeleteByID provides a mock function with given fields: ctx, resourceID +func (_m *ClientAPI) DeleteByID(ctx context.Context, resourceID string) (resources.DeleteByIDFuture, error) { + ret := _m.Called(ctx, resourceID) + + var r0 resources.DeleteByIDFuture + if rf, ok := ret.Get(0).(func(context.Context, string) resources.DeleteByIDFuture); ok { + r0 = rf(ctx, resourceID) + } else { + r0 = ret.Get(0).(resources.DeleteByIDFuture) + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, resourceID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Get provides a mock function with given fields: ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName +func (_m *ClientAPI) Get(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string) (resources.GenericResource, error) { + ret := _m.Called(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName) + + var r0 resources.GenericResource + if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string, string) resources.GenericResource); ok { + r0 = rf(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName) + } else { + r0 = ret.Get(0).(resources.GenericResource) + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string, string, string, string, string) error); ok { + r1 = rf(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetByID provides a mock function with given fields: ctx, resourceID +func (_m *ClientAPI) GetByID(ctx context.Context, resourceID string) (resources.GenericResource, error) { + ret := _m.Called(ctx, resourceID) + + var r0 resources.GenericResource + if rf, ok := ret.Get(0).(func(context.Context, string) resources.GenericResource); ok { + r0 = rf(ctx, resourceID) + } else { + r0 = ret.Get(0).(resources.GenericResource) + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, resourceID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// List provides a mock function with given fields: ctx, filter, expand, top +func (_m *ClientAPI) List(ctx context.Context, filter string, expand string, top *int32) (resources.ListResultPage, error) { + ret := _m.Called(ctx, filter, expand, top) + + var r0 resources.ListResultPage + if rf, ok := ret.Get(0).(func(context.Context, string, string, *int32) resources.ListResultPage); ok { + r0 = rf(ctx, filter, expand, top) + } else { + r0 = ret.Get(0).(resources.ListResultPage) + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string, string, *int32) error); ok { + r1 = rf(ctx, filter, expand, top) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ListByResourceGroup provides a mock function with given fields: ctx, resourceGroupName, filter, expand, top +func (_m *ClientAPI) ListByResourceGroup(ctx context.Context, resourceGroupName string, filter string, expand string, top *int32) (resources.ListResultPage, error) { + ret := _m.Called(ctx, resourceGroupName, filter, expand, top) + + var r0 resources.ListResultPage + if rf, ok := ret.Get(0).(func(context.Context, string, string, string, *int32) resources.ListResultPage); ok { + r0 = rf(ctx, resourceGroupName, filter, expand, top) + } else { + r0 = ret.Get(0).(resources.ListResultPage) + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string, string, string, *int32) error); ok { + r1 = rf(ctx, resourceGroupName, filter, expand, top) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MoveResources provides a mock function with given fields: ctx, sourceResourceGroupName, parameters +func (_m *ClientAPI) MoveResources(ctx context.Context, sourceResourceGroupName string, parameters resources.MoveInfo) (resources.MoveResourcesFuture, error) { + ret := _m.Called(ctx, sourceResourceGroupName, parameters) + + var r0 resources.MoveResourcesFuture + if rf, ok := ret.Get(0).(func(context.Context, string, resources.MoveInfo) resources.MoveResourcesFuture); ok { + r0 = rf(ctx, sourceResourceGroupName, parameters) + } else { + r0 = ret.Get(0).(resources.MoveResourcesFuture) + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string, resources.MoveInfo) error); ok { + r1 = rf(ctx, sourceResourceGroupName, parameters) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Update provides a mock function with given fields: ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, parameters +func (_m *ClientAPI) Update(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, parameters resources.GenericResource) (resources.UpdateFuture, error) { + ret := _m.Called(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, parameters) + + var r0 resources.UpdateFuture + if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string, string, resources.GenericResource) resources.UpdateFuture); ok { + r0 = rf(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, parameters) + } else { + r0 = ret.Get(0).(resources.UpdateFuture) + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string, string, string, string, string, resources.GenericResource) error); ok { + r1 = rf(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, parameters) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// UpdateByID provides a mock function with given fields: ctx, resourceID, parameters +func (_m *ClientAPI) UpdateByID(ctx context.Context, resourceID string, parameters resources.GenericResource) (resources.UpdateByIDFuture, error) { + ret := _m.Called(ctx, resourceID, parameters) + + var r0 resources.UpdateByIDFuture + if rf, ok := ret.Get(0).(func(context.Context, string, resources.GenericResource) resources.UpdateByIDFuture); ok { + r0 = rf(ctx, resourceID, parameters) + } else { + r0 = ret.Get(0).(resources.UpdateByIDFuture) + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string, resources.GenericResource) error); ok { + r1 = rf(ctx, resourceID, parameters) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ValidateMoveResources provides a mock function with given fields: ctx, sourceResourceGroupName, parameters +func (_m *ClientAPI) ValidateMoveResources(ctx context.Context, sourceResourceGroupName string, parameters resources.MoveInfo) (resources.ValidateMoveResourcesFuture, error) { + ret := _m.Called(ctx, sourceResourceGroupName, parameters) + + var r0 resources.ValidateMoveResourcesFuture + if rf, ok := ret.Get(0).(func(context.Context, string, resources.MoveInfo) resources.ValidateMoveResourcesFuture); ok { + r0 = rf(ctx, sourceResourceGroupName, parameters) + } else { + r0 = ret.Get(0).(resources.ValidateMoveResourcesFuture) + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, string, resources.MoveInfo) error); ok { + r1 = rf(ctx, sourceResourceGroupName, parameters) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +}