diff --git a/enumeration/remote/aws/repository/ec2_repository_test.go b/enumeration/remote/aws/repository/ec2_repository_test.go index 273a811b..f5b6c0f5 100644 --- a/enumeration/remote/aws/repository/ec2_repository_test.go +++ b/enumeration/remote/aws/repository/ec2_repository_test.go @@ -1,11 +1,11 @@ package repository import ( - cache2 "github.com/snyk/driftctl/enumeration/remote/cache" "strings" "testing" "github.com/pkg/errors" + "github.com/snyk/driftctl/enumeration/remote/cache" awstest "github.com/snyk/driftctl/test/aws" "github.com/stretchr/testify/mock" @@ -52,7 +52,7 @@ func Test_ec2Repository_ListAllImages(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - store := cache2.New(1) + store := cache.New(1) client := &awstest.MockFakeEC2{} tt.mocks(client) r := &ec2Repository{ @@ -131,7 +131,7 @@ func Test_ec2Repository_ListAllSnapshots(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - store := cache2.New(1) + store := cache.New(1) client := &awstest.MockFakeEC2{} tt.mocks(client) r := &ec2Repository{ @@ -206,7 +206,7 @@ func Test_ec2Repository_ListAllVolumes(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - store := cache2.New(1) + store := cache.New(1) client := &awstest.MockFakeEC2{} tt.mocks(client) r := &ec2Repository{ @@ -266,7 +266,7 @@ func Test_ec2Repository_ListAllAddresses(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - store := cache2.New(1) + store := cache.New(1) client := &awstest.MockFakeEC2{} tt.mocks(client) r := &ec2Repository{ @@ -326,7 +326,7 @@ func Test_ec2Repository_ListAllAddressesAssociation(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - store := cache2.New(1) + store := cache.New(1) client := &awstest.MockFakeEC2{} tt.mocks(client) r := &ec2Repository{ @@ -438,7 +438,7 @@ func Test_ec2Repository_ListAllInstances(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - store := cache2.New(1) + store := cache.New(1) client := &awstest.MockFakeEC2{} tt.mocks(client) r := &ec2Repository{ @@ -497,7 +497,7 @@ func Test_ec2Repository_ListAllKeyPairs(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - store := cache2.New(1) + store := cache.New(1) client := &awstest.MockFakeEC2{} tt.mocks(client) r := &ec2Repository{ @@ -581,7 +581,7 @@ func Test_ec2Repository_ListAllInternetGateways(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - store := cache2.New(1) + store := cache.New(1) client := &awstest.MockFakeEC2{} tt.mocks(client) r := &ec2Repository{ @@ -692,7 +692,7 @@ func Test_ec2Repository_ListAllSubnets(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - store := cache2.New(2) + store := cache.New(2) client := &awstest.MockFakeEC2{} tt.mocks(client) r := &ec2Repository{ @@ -786,7 +786,7 @@ func Test_ec2Repository_ListAllNatGateways(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - store := cache2.New(1) + store := cache.New(1) client := &awstest.MockFakeEC2{} tt.mocks(client) r := &ec2Repository{ @@ -978,7 +978,7 @@ func Test_ec2Repository_ListAllRouteTables(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - store := cache2.New(1) + store := cache.New(1) client := &awstest.MockFakeEC2{} tt.mocks(client) r := &ec2Repository{ @@ -1071,7 +1071,7 @@ func Test_ec2Repository_ListAllVPCs(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - store := cache2.New(2) + store := cache.New(2) client := &awstest.MockFakeEC2{} tt.mocks(client) r := &ec2Repository{ @@ -1156,7 +1156,7 @@ func Test_ec2Repository_ListAllSecurityGroups(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - store := cache2.New(2) + store := cache.New(2) client := &awstest.MockFakeEC2{} tt.mocks(client) r := &ec2Repository{ @@ -1247,7 +1247,7 @@ func Test_ec2Repository_ListAllNetworkACLs(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - store := cache2.New(2) + store := cache.New(2) client := &awstest.MockFakeEC2{} tt.mocks(client) r := &ec2Repository{ @@ -1325,7 +1325,7 @@ func Test_ec2Repository_DescribeLaunchTemplates(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - store := cache2.New(1) + store := cache.New(1) client := &awstest.MockFakeEC2{} tt.mocks(client) r := &ec2Repository{ @@ -1362,13 +1362,13 @@ func Test_ec2Repository_IsEbsEncryptionEnabledByDefault(t *testing.T) { tests := []struct { name string - mocks func(client *awstest.MockFakeEC2, store *cache2.MockCache) + mocks func(client *awstest.MockFakeEC2, store *cache.MockCache) want bool wantErr error }{ { name: "test that encryption enabled by default", - mocks: func(client *awstest.MockFakeEC2, store *cache2.MockCache) { + mocks: func(client *awstest.MockFakeEC2, store *cache.MockCache) { store.On("Get", "ec2IsEbsEncryptionEnabledByDefault"). Return(nil). Once() @@ -1387,7 +1387,7 @@ func Test_ec2Repository_IsEbsEncryptionEnabledByDefault(t *testing.T) { }, { name: "test that encryption enabled by default (cached)", - mocks: func(client *awstest.MockFakeEC2, store *cache2.MockCache) { + mocks: func(client *awstest.MockFakeEC2, store *cache.MockCache) { store.On("Get", "ec2IsEbsEncryptionEnabledByDefault"). Return(false). Once() @@ -1396,7 +1396,7 @@ func Test_ec2Repository_IsEbsEncryptionEnabledByDefault(t *testing.T) { }, { name: "error while getting default encryption value", - mocks: func(client *awstest.MockFakeEC2, store *cache2.MockCache) { + mocks: func(client *awstest.MockFakeEC2, store *cache.MockCache) { store.On("Get", "ec2IsEbsEncryptionEnabledByDefault"). Return(nil). Once() @@ -1410,7 +1410,7 @@ func Test_ec2Repository_IsEbsEncryptionEnabledByDefault(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - store := &cache2.MockCache{} + store := &cache.MockCache{} client := &awstest.MockFakeEC2{} tt.mocks(client, store) r := &ec2Repository{ diff --git a/enumeration/remote/aws/repository/rds_repository_test.go b/enumeration/remote/aws/repository/rds_repository_test.go index 639ffb8c..68b6827d 100644 --- a/enumeration/remote/aws/repository/rds_repository_test.go +++ b/enumeration/remote/aws/repository/rds_repository_test.go @@ -1,13 +1,13 @@ package repository import ( - cache2 "github.com/snyk/driftctl/enumeration/remote/cache" "strings" "testing" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/rds" "github.com/r3labs/diff/v2" + "github.com/snyk/driftctl/enumeration/remote/cache" awstest "github.com/snyk/driftctl/test/aws" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -55,7 +55,7 @@ func Test_rdsRepository_ListAllDBInstances(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - store := cache2.New(1) + store := cache.New(1) client := &awstest.MockFakeRDS{} tt.mocks(client) r := &rdsRepository{ @@ -127,7 +127,7 @@ func Test_rdsRepository_ListAllDBSubnetGroups(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - store := cache2.New(1) + store := cache.New(1) client := &awstest.MockFakeRDS{} tt.mocks(client) r := &rdsRepository{ @@ -160,13 +160,13 @@ func Test_rdsRepository_ListAllDBSubnetGroups(t *testing.T) { func Test_rdsRepository_ListAllDBClusters(t *testing.T) { tests := []struct { name string - mocks func(*awstest.MockFakeRDS, *cache2.MockCache) + mocks func(*awstest.MockFakeRDS, *cache.MockCache) want []*rds.DBCluster wantErr error }{ { name: "should list with 2 pages", - mocks: func(client *awstest.MockFakeRDS, store *cache2.MockCache) { + mocks: func(client *awstest.MockFakeRDS, store *cache.MockCache) { clusters := []*rds.DBCluster{ {DBClusterIdentifier: aws.String("1")}, {DBClusterIdentifier: aws.String("2")}, @@ -198,7 +198,7 @@ func Test_rdsRepository_ListAllDBClusters(t *testing.T) { }, { name: "should hit cache", - mocks: func(client *awstest.MockFakeRDS, store *cache2.MockCache) { + mocks: func(client *awstest.MockFakeRDS, store *cache.MockCache) { clusters := []*rds.DBCluster{ {DBClusterIdentifier: aws.String("1")}, {DBClusterIdentifier: aws.String("2")}, @@ -222,7 +222,7 @@ func Test_rdsRepository_ListAllDBClusters(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - store := &cache2.MockCache{} + store := &cache.MockCache{} client := &awstest.MockFakeRDS{} tt.mocks(client, store) r := &rdsRepository{ diff --git a/enumeration/remote/azurerm/repository/network_test.go b/enumeration/remote/azurerm/repository/network_test.go index 450064d9..27f8e2b8 100644 --- a/enumeration/remote/azurerm/repository/network_test.go +++ b/enumeration/remote/azurerm/repository/network_test.go @@ -3,13 +3,13 @@ package repository import ( "context" "fmt" - cache2 "github.com/snyk/driftctl/enumeration/remote/cache" "reflect" "testing" "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork" "github.com/pkg/errors" + "github.com/snyk/driftctl/enumeration/remote/cache" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -84,7 +84,7 @@ func Test_ListAllVirtualNetwork_MultiplesResults(t *testing.T) { fakeClient.On("ListAll", mock.Anything).Return(mockPager) - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("GetAndLock", "ListAllVirtualNetworks").Return(nil).Times(1) c.On("Unlock", "ListAllVirtualNetworks").Times(1) c.On("Put", "ListAllVirtualNetworks", expected).Return(true).Times(1) @@ -119,7 +119,7 @@ func Test_ListAllVirtualNetwork_MultiplesResults_WithCache(t *testing.T) { fakeClient := &mockVirtualNetworkClient{} - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("GetAndLock", "ListAllVirtualNetworks").Return(expected).Times(1) c.On("Unlock", "ListAllVirtualNetworks").Times(1) s := &networkRepository{ @@ -155,7 +155,7 @@ func Test_ListAllVirtualNetwork_Error_OnPageResponse(t *testing.T) { s := &networkRepository{ virtualNetworksClient: fakeClient, - cache: cache2.New(0), + cache: cache.New(0), } got, err := s.ListAllVirtualNetworks() @@ -180,7 +180,7 @@ func Test_ListAllVirtualNetwork_Error(t *testing.T) { s := &networkRepository{ virtualNetworksClient: fakeClient, - cache: cache2.New(0), + cache: cache.New(0), } got, err := s.ListAllVirtualNetworks() @@ -239,7 +239,7 @@ func Test_ListAllRouteTables_MultiplesResults(t *testing.T) { fakeClient.On("ListAll", mock.Anything).Return(mockPager) - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("GetAndLock", "ListAllRouteTables").Return(nil).Times(1) c.On("Unlock", "ListAllRouteTables").Times(1) c.On("Put", "ListAllRouteTables", expected).Return(true).Times(1) @@ -274,7 +274,7 @@ func Test_ListAllRouteTables_MultiplesResults_WithCache(t *testing.T) { fakeClient := &mockRouteTablesClient{} - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("GetAndLock", "ListAllRouteTables").Return(expected).Times(1) c.On("Unlock", "ListAllRouteTables").Times(1) s := &networkRepository{ @@ -310,7 +310,7 @@ func Test_ListAllRouteTables_Error_OnPageResponse(t *testing.T) { s := &networkRepository{ routeTableClient: fakeClient, - cache: cache2.New(0), + cache: cache.New(0), } got, err := s.ListAllRouteTables() @@ -335,7 +335,7 @@ func Test_ListAllRouteTables_Error(t *testing.T) { s := &networkRepository{ routeTableClient: fakeClient, - cache: cache2.New(0), + cache: cache.New(0), } got, err := s.ListAllRouteTables() @@ -423,7 +423,7 @@ func Test_ListAllSubnets_MultiplesResults(t *testing.T) { fakeClient.On("List", "test-dev", "network1", mock.Anything).Return(mockPager) - c := &cache2.MockCache{} + c := &cache.MockCache{} cacheKey := fmt.Sprintf("ListAllSubnets_%s", *network.ID) c.On("Get", cacheKey).Return(nil).Times(1) c.On("Put", cacheKey, expected).Return(true).Times(1) @@ -461,7 +461,7 @@ func Test_ListAllSubnets_MultiplesResults_WithCache(t *testing.T) { } fakeClient := &mockSubnetsClient{} - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("Get", "ListAllSubnets_networkID").Return(expected).Times(1) s := &networkRepository{ subnetsClient: fakeClient, @@ -503,7 +503,7 @@ func Test_ListAllSubnets_Error_OnPageResponse(t *testing.T) { s := &networkRepository{ subnetsClient: fakeClient, - cache: cache2.New(0), + cache: cache.New(0), } got, err := s.ListAllSubnets(network) @@ -535,7 +535,7 @@ func Test_ListAllSubnets_Error(t *testing.T) { s := &networkRepository{ subnetsClient: fakeClient, - cache: cache2.New(0), + cache: cache.New(0), } got, err := s.ListAllSubnets(network) @@ -561,7 +561,7 @@ func Test_ListAllSubnets_ErrorOnInvalidNetworkID(t *testing.T) { s := &networkRepository{ subnetsClient: fakeClient, - cache: cache2.New(0), + cache: cache.New(0), } got, err := s.ListAllSubnets(network) @@ -619,7 +619,7 @@ func Test_ListAllFirewalls_MultiplesResults(t *testing.T) { fakeClient.On("ListAll", mock.Anything).Return(mockPager) - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("Get", "ListAllFirewalls").Return(nil).Times(1) c.On("Put", "ListAllFirewalls", expected).Return(true).Times(1) s := &networkRepository{ @@ -653,7 +653,7 @@ func Test_ListAllFirewalls_MultiplesResults_WithCache(t *testing.T) { fakeClient := &mockFirewallsClient{} - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("Get", "ListAllFirewalls").Return(expected).Times(1) s := &networkRepository{ firewallsClient: fakeClient, @@ -688,7 +688,7 @@ func Test_ListAllFirewalls_Error_OnPageResponse(t *testing.T) { s := &networkRepository{ firewallsClient: fakeClient, - cache: cache2.New(0), + cache: cache.New(0), } got, err := s.ListAllFirewalls() @@ -713,7 +713,7 @@ func Test_ListAllFirewalls_Error(t *testing.T) { s := &networkRepository{ firewallsClient: fakeClient, - cache: cache2.New(0), + cache: cache.New(0), } got, err := s.ListAllFirewalls() @@ -772,7 +772,7 @@ func Test_ListAllPublicIPAddresses_MultiplesResults(t *testing.T) { fakeClient.On("ListAll", mock.Anything).Return(mockPager) - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("Get", "ListAllPublicIPAddresses").Return(nil).Times(1) c.On("Put", "ListAllPublicIPAddresses", expected).Return(true).Times(1) s := &networkRepository{ @@ -806,7 +806,7 @@ func Test_ListAllPublicIPAddresses_MultiplesResults_WithCache(t *testing.T) { fakeClient := &mockPublicIPAddressesClient{} - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("Get", "ListAllPublicIPAddresses").Return(expected).Times(1) s := &networkRepository{ publicIPAddressesClient: fakeClient, @@ -841,7 +841,7 @@ func Test_ListAllPublicIPAddresses_Error_OnPageResponse(t *testing.T) { s := &networkRepository{ publicIPAddressesClient: fakeClient, - cache: cache2.New(0), + cache: cache.New(0), } got, err := s.ListAllPublicIPAddresses() @@ -866,7 +866,7 @@ func Test_ListAllPublicIPAddresses_Error(t *testing.T) { s := &networkRepository{ publicIPAddressesClient: fakeClient, - cache: cache2.New(0), + cache: cache.New(0), } got, err := s.ListAllPublicIPAddresses() @@ -895,13 +895,13 @@ func Test_Network_ListAllSecurityGroups(t *testing.T) { testcases := []struct { name string - mocks func(*mockNetworkSecurityGroupsListAllPager, *cache2.MockCache) + mocks func(*mockNetworkSecurityGroupsListAllPager, *cache.MockCache) expected []*armnetwork.NetworkSecurityGroup wantErr string }{ { name: "should return security groups", - mocks: func(pager *mockNetworkSecurityGroupsListAllPager, mockCache *cache2.MockCache) { + mocks: func(pager *mockNetworkSecurityGroupsListAllPager, mockCache *cache.MockCache) { pager.On("NextPage", context.Background()).Return(true).Times(1) pager.On("NextPage", context.Background()).Return(false).Times(1) pager.On("PageResponse").Return(armnetwork.NetworkSecurityGroupsListAllResponse{ @@ -920,14 +920,14 @@ func Test_Network_ListAllSecurityGroups(t *testing.T) { }, { name: "should hit cache and return security groups", - mocks: func(pager *mockNetworkSecurityGroupsListAllPager, mockCache *cache2.MockCache) { + mocks: func(pager *mockNetworkSecurityGroupsListAllPager, mockCache *cache.MockCache) { mockCache.On("Get", "networkListAllSecurityGroups").Return(expectedResults).Times(1) }, expected: expectedResults, }, { name: "should return remote error", - mocks: func(pager *mockNetworkSecurityGroupsListAllPager, mockCache *cache2.MockCache) { + mocks: func(pager *mockNetworkSecurityGroupsListAllPager, mockCache *cache.MockCache) { pager.On("NextPage", context.Background()).Return(true).Times(1) pager.On("NextPage", context.Background()).Return(false).Times(1) pager.On("PageResponse").Return(armnetwork.NetworkSecurityGroupsListAllResponse{}).Times(1) @@ -943,7 +943,7 @@ func Test_Network_ListAllSecurityGroups(t *testing.T) { t.Run(tt.name, func(t *testing.T) { fakePager := &mockNetworkSecurityGroupsListAllPager{} fakeClient := &mockNetworkSecurityGroupsClient{} - mockCache := &cache2.MockCache{} + mockCache := &cache.MockCache{} fakeClient.On("ListAll", (*armnetwork.NetworkSecurityGroupsListAllOptions)(nil)).Return(fakePager).Maybe() @@ -988,13 +988,13 @@ func Test_Network_ListAllLoadBalancers(t *testing.T) { testcases := []struct { name string - mocks func(*mockLoadBalancersListAllPager, *cache2.MockCache) + mocks func(*mockLoadBalancersListAllPager, *cache.MockCache) expected []*armnetwork.LoadBalancer wantErr string }{ { name: "should return load balancers", - mocks: func(pager *mockLoadBalancersListAllPager, mockCache *cache2.MockCache) { + mocks: func(pager *mockLoadBalancersListAllPager, mockCache *cache.MockCache) { pager.On("NextPage", context.Background()).Return(true).Times(1) pager.On("NextPage", context.Background()).Return(false).Times(1) pager.On("PageResponse").Return(armnetwork.LoadBalancersListAllResponse{ @@ -1014,7 +1014,7 @@ func Test_Network_ListAllLoadBalancers(t *testing.T) { }, { name: "should hit cache and return load balancers", - mocks: func(pager *mockLoadBalancersListAllPager, mockCache *cache2.MockCache) { + mocks: func(pager *mockLoadBalancersListAllPager, mockCache *cache.MockCache) { mockCache.On("GetAndLock", "networkListAllLoadBalancers").Return(expectedResults).Times(1) mockCache.On("Unlock", "networkListAllLoadBalancers").Return(nil).Times(1) }, @@ -1022,7 +1022,7 @@ func Test_Network_ListAllLoadBalancers(t *testing.T) { }, { name: "should return remote error", - mocks: func(pager *mockLoadBalancersListAllPager, mockCache *cache2.MockCache) { + mocks: func(pager *mockLoadBalancersListAllPager, mockCache *cache.MockCache) { pager.On("NextPage", context.Background()).Return(true).Times(1) pager.On("NextPage", context.Background()).Return(false).Times(1) pager.On("PageResponse").Return(armnetwork.LoadBalancersListAllResponse{}).Times(1) @@ -1039,7 +1039,7 @@ func Test_Network_ListAllLoadBalancers(t *testing.T) { t.Run(tt.name, func(t *testing.T) { fakePager := &mockLoadBalancersListAllPager{} fakeClient := &mockLoadBalancersClient{} - mockCache := &cache2.MockCache{} + mockCache := &cache.MockCache{} fakeClient.On("ListAll", (*armnetwork.LoadBalancersListAllOptions)(nil)).Return(fakePager).Maybe() @@ -1085,7 +1085,7 @@ func Test_Network_ListLoadBalancerRules(t *testing.T) { testcases := []struct { name string loadBalancer *armnetwork.LoadBalancer - mocks func(*mockLoadBalancerRulesClient, *mockLoadBalancerRulesListAllPager, *cache2.MockCache) + mocks func(*mockLoadBalancerRulesClient, *mockLoadBalancerRulesListAllPager, *cache.MockCache) expected []*armnetwork.LoadBalancingRule wantErr string }{ @@ -1094,7 +1094,7 @@ func Test_Network_ListLoadBalancerRules(t *testing.T) { loadBalancer: &armnetwork.LoadBalancer{ Resource: armnetwork.Resource{ID: to.StringPtr("/subscriptions/xxx/resourceGroups/driftctl/providers/Microsoft.Network/loadBalancers/TestLoadBalancer/frontendIPConfigurations/PublicIPAddress")}, }, - mocks: func(client *mockLoadBalancerRulesClient, pager *mockLoadBalancerRulesListAllPager, mockCache *cache2.MockCache) { + mocks: func(client *mockLoadBalancerRulesClient, pager *mockLoadBalancerRulesListAllPager, mockCache *cache.MockCache) { client.On("List", "driftctl", "PublicIPAddress", &armnetwork.LoadBalancerLoadBalancingRulesListOptions{}).Return(pager) pager.On("NextPage", context.Background()).Return(true).Times(1) @@ -1118,7 +1118,7 @@ func Test_Network_ListLoadBalancerRules(t *testing.T) { loadBalancer: &armnetwork.LoadBalancer{ Resource: armnetwork.Resource{ID: to.StringPtr("lb-1")}, }, - mocks: func(client *mockLoadBalancerRulesClient, pager *mockLoadBalancerRulesListAllPager, mockCache *cache2.MockCache) { + mocks: func(client *mockLoadBalancerRulesClient, pager *mockLoadBalancerRulesListAllPager, mockCache *cache.MockCache) { mockCache.On("Get", "networkListLoadBalancerRules_lb-1").Return(expectedResults).Times(1) }, expected: expectedResults, @@ -1128,7 +1128,7 @@ func Test_Network_ListLoadBalancerRules(t *testing.T) { loadBalancer: &armnetwork.LoadBalancer{ Resource: armnetwork.Resource{ID: to.StringPtr("/subscriptions/xxx/resourceGroups/driftctl/providers/Microsoft.Network/loadBalancers/TestLoadBalancer/frontendIPConfigurations/PublicIPAddress")}, }, - mocks: func(client *mockLoadBalancerRulesClient, pager *mockLoadBalancerRulesListAllPager, mockCache *cache2.MockCache) { + mocks: func(client *mockLoadBalancerRulesClient, pager *mockLoadBalancerRulesListAllPager, mockCache *cache.MockCache) { client.On("List", "driftctl", "PublicIPAddress", &armnetwork.LoadBalancerLoadBalancingRulesListOptions{}).Return(pager) pager.On("NextPage", context.Background()).Return(true).Times(1) @@ -1146,7 +1146,7 @@ func Test_Network_ListLoadBalancerRules(t *testing.T) { t.Run(tt.name, func(t *testing.T) { fakePager := &mockLoadBalancerRulesListAllPager{} fakeClient := &mockLoadBalancerRulesClient{} - mockCache := &cache2.MockCache{} + mockCache := &cache.MockCache{} tt.mocks(fakeClient, fakePager, mockCache) diff --git a/enumeration/remote/azurerm/repository/privatedns_test.go b/enumeration/remote/azurerm/repository/privatedns_test.go index fddcb0c4..93cb4178 100644 --- a/enumeration/remote/azurerm/repository/privatedns_test.go +++ b/enumeration/remote/azurerm/repository/privatedns_test.go @@ -1,13 +1,13 @@ package repository import ( - cache2 "github.com/snyk/driftctl/enumeration/remote/cache" "reflect" "testing" "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/privatedns/armprivatedns" "github.com/pkg/errors" + "github.com/snyk/driftctl/enumeration/remote/cache" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -99,7 +99,7 @@ func Test_ListAllPrivateZones_MultiplesResults(t *testing.T) { fakeClient.On("List", mock.Anything).Return(mockPager) - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("GetAndLock", "privateDNSListAllPrivateZones").Return(nil).Times(1) c.On("Unlock", "privateDNSListAllPrivateZones").Times(1) c.On("Put", "privateDNSListAllPrivateZones", expected).Return(true).Times(1) @@ -136,7 +136,7 @@ func Test_ListAllPrivateZones_MultiplesResults_WithCache(t *testing.T) { fakeClient := &mockPrivateZonesClient{} - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("GetAndLock", "privateDNSListAllPrivateZones").Return(expected).Times(1) c.On("Unlock", "privateDNSListAllPrivateZones").Times(1) @@ -173,7 +173,7 @@ func Test_ListAllPrivateZones_Error(t *testing.T) { s := &privateDNSRepository{ zoneClient: fakeClient, - cache: cache2.New(0), + cache: cache.New(0), } got, err := s.ListAllPrivateZones() @@ -281,7 +281,7 @@ func Test_ListAllARecords_MultiplesResults(t *testing.T) { fakeRecordSetClient.On("List", "rgid", "zone", (*armprivatedns.RecordSetsListOptions)(nil)).Return(mockPager) - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("GetAndLock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return(nil).Times(1) c.On("Unlock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return().Times(1) c.On("Put", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com", mock.Anything).Return(true).Times(1) @@ -330,7 +330,7 @@ func Test_ListAllARecords_MultiplesResults_WithCache(t *testing.T) { fakeRecordSetClient := &mockPrivateRecordSetClient{} - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("GetAndLock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return(expected).Times(1) c.On("Unlock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Times(1) s := &privateDNSRepository{ @@ -373,7 +373,7 @@ func Test_ListAllARecords_Error(t *testing.T) { s := &privateDNSRepository{ recordClient: fakeClient, - cache: cache2.New(0), + cache: cache.New(0), } got, err := s.ListAllARecords(&armprivatedns.PrivateZone{ TrackedResource: armprivatedns.TrackedResource{ @@ -488,7 +488,7 @@ func Test_ListAllAAAARecords_MultiplesResults(t *testing.T) { fakeRecordSetClient.On("List", "rgid", "zone", (*armprivatedns.RecordSetsListOptions)(nil)).Return(mockPager) - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("GetAndLock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return(nil).Times(1) c.On("Unlock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return().Times(1) c.On("Put", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com", mock.Anything).Return(true).Times(1) @@ -537,7 +537,7 @@ func Test_ListAllAAAARecords_MultiplesResults_WithCache(t *testing.T) { fakeRecordSetClient := &mockPrivateRecordSetClient{} - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("GetAndLock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return(expected).Times(1) c.On("Unlock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Times(1) s := &privateDNSRepository{ @@ -580,7 +580,7 @@ func Test_ListAllAAAARecords_Error(t *testing.T) { s := &privateDNSRepository{ recordClient: fakeClient, - cache: cache2.New(0), + cache: cache.New(0), } got, err := s.ListAllAAAARecords(&armprivatedns.PrivateZone{ TrackedResource: armprivatedns.TrackedResource{ @@ -695,7 +695,7 @@ func Test_ListAllCNAMERecords_MultiplesResults(t *testing.T) { fakeRecordSetClient.On("List", "rgid", "zone", (*armprivatedns.RecordSetsListOptions)(nil)).Return(mockPager) - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("GetAndLock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return(nil).Times(1) c.On("Unlock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return().Times(1) c.On("Put", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com", mock.Anything).Return(true).Times(1) @@ -744,7 +744,7 @@ func Test_ListAllCNAMERecords_MultiplesResults_WithCache(t *testing.T) { fakeRecordSetClient := &mockPrivateRecordSetClient{} - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("GetAndLock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return(expected).Times(1) c.On("Unlock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return().Times(1) @@ -789,7 +789,7 @@ func Test_ListAllCNAMERecords_Error(t *testing.T) { s := &privateDNSRepository{ recordClient: fakeClient, - cache: cache2.New(0), + cache: cache.New(0), } got, err := s.ListAllCNAMERecords(&armprivatedns.PrivateZone{ TrackedResource: armprivatedns.TrackedResource{ @@ -904,7 +904,7 @@ func Test_ListAllPTRRecords_MultiplesResults(t *testing.T) { fakeRecordSetClient.On("List", "rgid", "zone", (*armprivatedns.RecordSetsListOptions)(nil)).Return(mockPager) - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("GetAndLock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return(nil).Times(1) c.On("Unlock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return().Times(1) c.On("Put", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com", mock.Anything).Return(true).Times(1) @@ -953,7 +953,7 @@ func Test_ListAllPTRRecords_MultiplesResults_WithCache(t *testing.T) { fakeRecordSetClient := &mockPrivateRecordSetClient{} - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("GetAndLock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return(expected).Times(1) c.On("Unlock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Times(1) s := &privateDNSRepository{ @@ -996,7 +996,7 @@ func Test_ListAllPTRRecords_Error(t *testing.T) { s := &privateDNSRepository{ recordClient: fakeClient, - cache: cache2.New(0), + cache: cache.New(0), } got, err := s.ListAllPTRRecords(&armprivatedns.PrivateZone{ TrackedResource: armprivatedns.TrackedResource{ @@ -1110,7 +1110,7 @@ func Test_ListAllMXRecords_MultiplesResults(t *testing.T) { fakeRecordSetClient.On("List", "rgid", "zone", (*armprivatedns.RecordSetsListOptions)(nil)).Return(mockPager) - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("GetAndLock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return(nil).Times(1) c.On("Unlock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return().Times(1) c.On("Put", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com", mock.Anything).Return(true).Times(1) @@ -1158,7 +1158,7 @@ func Test_ListAllMXRecords_MultiplesResults_WithCache(t *testing.T) { fakeRecordSetClient := &mockPrivateRecordSetClient{} - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("GetAndLock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return(expected).Times(1) c.On("Unlock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Times(1) s := &privateDNSRepository{ @@ -1203,7 +1203,7 @@ func Test_ListAllMXRecords_Error(t *testing.T) { s := &privateDNSRepository{ recordClient: fakeClient, - cache: cache2.New(0), + cache: cache.New(0), } got, err := s.ListAllMXRecords(&armprivatedns.PrivateZone{ @@ -1319,7 +1319,7 @@ func Test_ListAllSRVRecords_MultiplesResults(t *testing.T) { fakeRecordSetClient.On("List", "rgid", "zone", (*armprivatedns.RecordSetsListOptions)(nil)).Return(mockPager) - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("GetAndLock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return(nil).Times(1) c.On("Unlock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return().Times(1) c.On("Put", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com", mock.Anything).Return(true).Times(1) @@ -1368,7 +1368,7 @@ func Test_ListAllSRVRecords_MultiplesResults_WithCache(t *testing.T) { fakeRecordSetClient := &mockPrivateRecordSetClient{} - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("GetAndLock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return(expected).Times(1) c.On("Unlock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Times(1) s := &privateDNSRepository{ @@ -1411,7 +1411,7 @@ func Test_ListAllSRVRecords_Error(t *testing.T) { s := &privateDNSRepository{ recordClient: fakeClient, - cache: cache2.New(0), + cache: cache.New(0), } got, err := s.ListAllSRVRecords(&armprivatedns.PrivateZone{ TrackedResource: armprivatedns.TrackedResource{ @@ -1526,7 +1526,7 @@ func Test_ListAllTXTRecords_MultiplesResults(t *testing.T) { fakeRecordSetClient.On("List", "rgid", "zone", (*armprivatedns.RecordSetsListOptions)(nil)).Return(mockPager) - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("GetAndLock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return(nil).Times(1) c.On("Unlock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return().Times(1) c.On("Put", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com", mock.Anything).Return(true).Times(1) @@ -1575,7 +1575,7 @@ func Test_ListAllTXTRecords_MultiplesResults_WithCache(t *testing.T) { fakeRecordSetClient := &mockPrivateRecordSetClient{} - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("GetAndLock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return(expected).Times(1) c.On("Unlock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Times(1) s := &privateDNSRepository{ @@ -1618,7 +1618,7 @@ func Test_ListAllTXTRecords_Error(t *testing.T) { s := &privateDNSRepository{ recordClient: fakeClient, - cache: cache2.New(0), + cache: cache.New(0), } got, err := s.ListAllTXTRecords(&armprivatedns.PrivateZone{ TrackedResource: armprivatedns.TrackedResource{ diff --git a/enumeration/remote/azurerm/repository/storage_test.go b/enumeration/remote/azurerm/repository/storage_test.go index 9ec4bb48..2deea26e 100644 --- a/enumeration/remote/azurerm/repository/storage_test.go +++ b/enumeration/remote/azurerm/repository/storage_test.go @@ -1,13 +1,13 @@ package repository import ( - cache2 "github.com/snyk/driftctl/enumeration/remote/cache" "reflect" "testing" "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage" "github.com/pkg/errors" + "github.com/snyk/driftctl/enumeration/remote/cache" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -98,7 +98,7 @@ func Test_ListAllStorageAccount_MultiplesResults(t *testing.T) { fakeClient.On("List", mock.Anything).Return(mockPager) - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("GetAndLock", "ListAllStorageAccount").Return(nil).Times(1) c.On("Unlock", "ListAllStorageAccount").Times(1) c.On("Put", "ListAllStorageAccount", expected).Return(true).Times(1) @@ -135,7 +135,7 @@ func Test_ListAllStorageAccount_MultiplesResults_WithCache(t *testing.T) { fakeClient := &mockStorageAccountClient{} - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("GetAndLock", "ListAllStorageAccount").Return(expected).Times(1) c.On("Unlock", "ListAllStorageAccount").Times(1) s := &storageRepository{ @@ -171,7 +171,7 @@ func Test_ListAllStorageAccount_Error(t *testing.T) { s := &storageRepository{ storageAccountsClient: fakeClient, - cache: cache2.New(0), + cache: cache.New(0), } got, err := s.ListAllStorageAccount() @@ -258,7 +258,7 @@ func Test_ListAllStorageContainer_MultiplesResults(t *testing.T) { fakeClient.On("List", "foobar", "testeliedriftctl", (*armstorage.BlobContainersListOptions)(nil)).Return(mockPager) - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("Get", "ListAllStorageContainer_testeliedriftctl").Return(nil).Times(1) c.On("Put", "ListAllStorageContainer_testeliedriftctl", expected).Return(true).Times(1) s := &storageRepository{ @@ -295,7 +295,7 @@ func Test_ListAllStorageContainer_MultiplesResults_WithCache(t *testing.T) { fakeClient := &mockBlobContainerClient{} - c := &cache2.MockCache{} + c := &cache.MockCache{} c.On("Get", "ListAllStorageContainer_testeliedriftctl").Return(expected).Times(1) s := &storageRepository{ blobContainerClient: fakeClient, @@ -328,7 +328,7 @@ func Test_ListAllStorageContainer_InvalidStorageAccountResourceID(t *testing.T) s := &storageRepository{ blobContainerClient: fakeClient, - cache: cache2.New(0), + cache: cache.New(0), } got, err := s.ListAllStorageContainer(&account) @@ -361,7 +361,7 @@ func Test_ListAllStorageContainer_Error(t *testing.T) { s := &storageRepository{ blobContainerClient: fakeClient, - cache: cache2.New(0), + cache: cache.New(0), } got, err := s.ListAllStorageContainer(&account)