2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-03-22 11:03:15 -04:00
|
|
|
package azure
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-06-30 09:24:36 -04:00
|
|
|
"testing"
|
2022-03-22 11:03:15 -04:00
|
|
|
|
2022-07-27 16:02:33 -04:00
|
|
|
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
|
|
|
|
armcomputev2 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v2"
|
2022-03-22 11:03:15 -04:00
|
|
|
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork"
|
|
|
|
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
|
2022-06-30 09:24:36 -04:00
|
|
|
"go.uber.org/goleak"
|
2022-03-22 11:03:15 -04:00
|
|
|
)
|
|
|
|
|
2022-06-30 09:24:36 -04:00
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
goleak.VerifyTestMain(m,
|
|
|
|
// https://github.com/census-instrumentation/opencensus-go/issues/1262
|
|
|
|
goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-03-22 11:03:15 -04:00
|
|
|
type stubIMDSAPI struct {
|
2022-08-29 05:54:30 -04:00
|
|
|
providerIDErr error
|
|
|
|
providerID string
|
|
|
|
subscriptionIDErr error
|
|
|
|
subscriptionID string
|
|
|
|
resourceGroupErr error
|
|
|
|
resourceGroup string
|
|
|
|
uidErr error
|
|
|
|
uid string
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
2022-08-29 05:54:30 -04:00
|
|
|
func (a *stubIMDSAPI) ProviderID(ctx context.Context) (string, error) {
|
|
|
|
return a.providerID, a.providerIDErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *stubIMDSAPI) SubscriptionID(ctx context.Context) (string, error) {
|
|
|
|
return a.subscriptionID, a.subscriptionIDErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *stubIMDSAPI) ResourceGroup(ctx context.Context) (string, error) {
|
|
|
|
return a.resourceGroup, a.resourceGroupErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *stubIMDSAPI) UID(ctx context.Context) (string, error) {
|
|
|
|
return a.uid, a.uidErr
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type stubNetworkInterfacesAPI struct {
|
|
|
|
getInterface armnetwork.Interface
|
|
|
|
getErr error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *stubNetworkInterfacesAPI) GetVirtualMachineScaleSetNetworkInterface(ctx context.Context, resourceGroupName string,
|
|
|
|
virtualMachineScaleSetName string, virtualmachineIndex string, networkInterfaceName string,
|
|
|
|
options *armnetwork.InterfacesClientGetVirtualMachineScaleSetNetworkInterfaceOptions,
|
|
|
|
) (armnetwork.InterfacesClientGetVirtualMachineScaleSetNetworkInterfaceResponse, error) {
|
|
|
|
return armnetwork.InterfacesClientGetVirtualMachineScaleSetNetworkInterfaceResponse{
|
2022-07-27 16:02:33 -04:00
|
|
|
Interface: a.getInterface,
|
2022-03-22 11:03:15 -04:00
|
|
|
}, a.getErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *stubNetworkInterfacesAPI) Get(ctx context.Context, resourceGroupName string, networkInterfaceName string,
|
|
|
|
options *armnetwork.InterfacesClientGetOptions,
|
|
|
|
) (armnetwork.InterfacesClientGetResponse, error) {
|
|
|
|
return armnetwork.InterfacesClientGetResponse{
|
2022-07-27 16:02:33 -04:00
|
|
|
Interface: a.getInterface,
|
2022-03-22 11:03:15 -04:00
|
|
|
}, a.getErr
|
|
|
|
}
|
|
|
|
|
|
|
|
type stubVirtualMachineScaleSetVMsAPI struct {
|
2022-07-27 16:02:33 -04:00
|
|
|
getVM armcomputev2.VirtualMachineScaleSetVM
|
|
|
|
getErr error
|
|
|
|
pager *stubVirtualMachineScaleSetVMPager
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
2022-07-27 16:02:33 -04:00
|
|
|
func (a *stubVirtualMachineScaleSetVMsAPI) Get(ctx context.Context, resourceGroupName string, vmScaleSetName string, instanceID string, options *armcomputev2.VirtualMachineScaleSetVMsClientGetOptions) (armcomputev2.VirtualMachineScaleSetVMsClientGetResponse, error) {
|
|
|
|
return armcomputev2.VirtualMachineScaleSetVMsClientGetResponse{
|
|
|
|
VirtualMachineScaleSetVM: a.getVM,
|
2022-03-22 11:03:15 -04:00
|
|
|
}, a.getErr
|
|
|
|
}
|
|
|
|
|
2022-07-27 16:02:33 -04:00
|
|
|
func (a *stubVirtualMachineScaleSetVMsAPI) NewListPager(resourceGroupName string, virtualMachineScaleSetName string, options *armcomputev2.VirtualMachineScaleSetVMsClientListOptions) *runtime.Pager[armcomputev2.VirtualMachineScaleSetVMsClientListResponse] {
|
|
|
|
return runtime.NewPager(runtime.PagingHandler[armcomputev2.VirtualMachineScaleSetVMsClientListResponse]{
|
|
|
|
More: a.pager.moreFunc(),
|
|
|
|
Fetcher: a.pager.fetcherFunc(),
|
|
|
|
})
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type stubVirtualMachineScaleSetsClientListPager struct {
|
2022-07-27 16:02:33 -04:00
|
|
|
list []armcomputev2.VirtualMachineScaleSet
|
|
|
|
fetchErr error
|
|
|
|
more bool
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
2022-07-27 16:02:33 -04:00
|
|
|
func (p *stubVirtualMachineScaleSetsClientListPager) moreFunc() func(armcomputev2.VirtualMachineScaleSetsClientListResponse) bool {
|
|
|
|
return func(armcomputev2.VirtualMachineScaleSetsClientListResponse) bool {
|
|
|
|
return p.more
|
|
|
|
}
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
2022-07-27 16:02:33 -04:00
|
|
|
func (p *stubVirtualMachineScaleSetsClientListPager) fetcherFunc() func(context.Context, *armcomputev2.VirtualMachineScaleSetsClientListResponse) (armcomputev2.VirtualMachineScaleSetsClientListResponse, error) {
|
|
|
|
return func(context.Context, *armcomputev2.VirtualMachineScaleSetsClientListResponse) (armcomputev2.VirtualMachineScaleSetsClientListResponse, error) {
|
|
|
|
page := make([]*armcomputev2.VirtualMachineScaleSet, len(p.list))
|
|
|
|
for i := range p.list {
|
|
|
|
page[i] = &p.list[i]
|
|
|
|
}
|
|
|
|
return armcomputev2.VirtualMachineScaleSetsClientListResponse{
|
|
|
|
VirtualMachineScaleSetListResult: armcomputev2.VirtualMachineScaleSetListResult{
|
|
|
|
Value: page,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
2022-07-27 16:02:33 -04:00
|
|
|
}, p.fetchErr
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type stubScaleSetsAPI struct {
|
2022-07-27 16:02:33 -04:00
|
|
|
pager *stubVirtualMachineScaleSetsClientListPager
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
2022-07-27 16:02:33 -04:00
|
|
|
func (a *stubScaleSetsAPI) NewListPager(resourceGroupName string, options *armcomputev2.VirtualMachineScaleSetsClientListOptions) *runtime.Pager[armcomputev2.VirtualMachineScaleSetsClientListResponse] {
|
|
|
|
return runtime.NewPager(runtime.PagingHandler[armcomputev2.VirtualMachineScaleSetsClientListResponse]{
|
|
|
|
More: a.pager.moreFunc(),
|
|
|
|
Fetcher: a.pager.fetcherFunc(),
|
|
|
|
})
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type stubTagsAPI struct {
|
|
|
|
createOrUpdateAtScopeErr error
|
|
|
|
updateAtScopeErr error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *stubTagsAPI) CreateOrUpdateAtScope(ctx context.Context, scope string, parameters armresources.TagsResource, options *armresources.TagsClientCreateOrUpdateAtScopeOptions) (armresources.TagsClientCreateOrUpdateAtScopeResponse, error) {
|
|
|
|
return armresources.TagsClientCreateOrUpdateAtScopeResponse{}, a.createOrUpdateAtScopeErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *stubTagsAPI) UpdateAtScope(ctx context.Context, scope string, parameters armresources.TagsPatchResource, options *armresources.TagsClientUpdateAtScopeOptions) (armresources.TagsClientUpdateAtScopeResponse, error) {
|
|
|
|
return armresources.TagsClientUpdateAtScopeResponse{}, a.updateAtScopeErr
|
|
|
|
}
|
2022-05-24 04:04:42 -04:00
|
|
|
|
|
|
|
type stubSecurityGroupsClientListPager struct {
|
2022-07-27 16:02:33 -04:00
|
|
|
list []armnetwork.SecurityGroup
|
|
|
|
fetchErr error
|
|
|
|
more bool
|
2022-05-24 04:04:42 -04:00
|
|
|
}
|
|
|
|
|
2022-07-27 16:02:33 -04:00
|
|
|
func (p *stubSecurityGroupsClientListPager) moreFunc() func(armnetwork.SecurityGroupsClientListResponse) bool {
|
|
|
|
return func(armnetwork.SecurityGroupsClientListResponse) bool {
|
|
|
|
return p.more
|
|
|
|
}
|
2022-05-24 04:04:42 -04:00
|
|
|
}
|
|
|
|
|
2022-07-27 16:02:33 -04:00
|
|
|
func (p *stubSecurityGroupsClientListPager) fetcherFunc() func(context.Context, *armnetwork.SecurityGroupsClientListResponse) (armnetwork.SecurityGroupsClientListResponse, error) {
|
|
|
|
return func(context.Context, *armnetwork.SecurityGroupsClientListResponse) (armnetwork.SecurityGroupsClientListResponse, error) {
|
|
|
|
page := make([]*armnetwork.SecurityGroup, len(p.list))
|
|
|
|
for i := range p.list {
|
|
|
|
page[i] = &p.list[i]
|
|
|
|
}
|
|
|
|
return armnetwork.SecurityGroupsClientListResponse{
|
2022-05-24 04:04:42 -04:00
|
|
|
SecurityGroupListResult: armnetwork.SecurityGroupListResult{
|
2022-07-27 16:02:33 -04:00
|
|
|
Value: page,
|
2022-05-24 04:04:42 -04:00
|
|
|
},
|
2022-07-27 16:02:33 -04:00
|
|
|
}, p.fetchErr
|
2022-05-24 04:04:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type stubSecurityGroupsAPI struct {
|
2022-07-27 16:02:33 -04:00
|
|
|
pager *stubSecurityGroupsClientListPager
|
2022-05-24 04:04:42 -04:00
|
|
|
}
|
|
|
|
|
2022-07-27 16:02:33 -04:00
|
|
|
func (a *stubSecurityGroupsAPI) NewListPager(resourceGroupName string, options *armnetwork.SecurityGroupsClientListOptions) *runtime.Pager[armnetwork.SecurityGroupsClientListResponse] {
|
|
|
|
return runtime.NewPager(runtime.PagingHandler[armnetwork.SecurityGroupsClientListResponse]{
|
|
|
|
More: a.pager.moreFunc(),
|
|
|
|
Fetcher: a.pager.fetcherFunc(),
|
|
|
|
})
|
2022-05-24 04:04:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type stubVirtualNetworksClientListPager struct {
|
2022-07-27 16:02:33 -04:00
|
|
|
list []armnetwork.VirtualNetwork
|
|
|
|
fetchErr error
|
|
|
|
more bool
|
2022-05-24 04:04:42 -04:00
|
|
|
}
|
|
|
|
|
2022-07-27 16:02:33 -04:00
|
|
|
func (p *stubVirtualNetworksClientListPager) moreFunc() func(armnetwork.VirtualNetworksClientListResponse) bool {
|
|
|
|
return func(armnetwork.VirtualNetworksClientListResponse) bool {
|
|
|
|
return p.more
|
|
|
|
}
|
2022-05-24 04:04:42 -04:00
|
|
|
}
|
|
|
|
|
2022-07-27 16:02:33 -04:00
|
|
|
func (p *stubVirtualNetworksClientListPager) fetcherFunc() func(context.Context, *armnetwork.VirtualNetworksClientListResponse) (armnetwork.VirtualNetworksClientListResponse, error) {
|
|
|
|
return func(context.Context, *armnetwork.VirtualNetworksClientListResponse) (armnetwork.VirtualNetworksClientListResponse, error) {
|
|
|
|
page := make([]*armnetwork.VirtualNetwork, len(p.list))
|
|
|
|
for i := range p.list {
|
|
|
|
page[i] = &p.list[i]
|
|
|
|
}
|
|
|
|
return armnetwork.VirtualNetworksClientListResponse{
|
2022-05-24 04:04:42 -04:00
|
|
|
VirtualNetworkListResult: armnetwork.VirtualNetworkListResult{
|
2022-07-27 16:02:33 -04:00
|
|
|
Value: page,
|
2022-05-24 04:04:42 -04:00
|
|
|
},
|
2022-07-27 16:02:33 -04:00
|
|
|
}, p.fetchErr
|
2022-05-24 04:04:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type stubVirtualNetworksAPI struct {
|
2022-07-27 16:02:33 -04:00
|
|
|
pager *stubVirtualNetworksClientListPager
|
2022-05-24 04:04:42 -04:00
|
|
|
}
|
|
|
|
|
2022-07-27 16:02:33 -04:00
|
|
|
func (a *stubVirtualNetworksAPI) NewListPager(resourceGroupName string, options *armnetwork.VirtualNetworksClientListOptions) *runtime.Pager[armnetwork.VirtualNetworksClientListResponse] {
|
|
|
|
return runtime.NewPager(runtime.PagingHandler[armnetwork.VirtualNetworksClientListResponse]{
|
|
|
|
More: a.pager.moreFunc(),
|
|
|
|
Fetcher: a.pager.fetcherFunc(),
|
|
|
|
})
|
2022-05-24 04:04:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type stubLoadBalancersAPI struct {
|
2022-07-27 16:02:33 -04:00
|
|
|
pager *stubLoadBalancersClientListPager
|
2022-05-24 04:04:42 -04:00
|
|
|
}
|
|
|
|
|
2022-07-27 16:02:33 -04:00
|
|
|
func (a *stubLoadBalancersAPI) NewListPager(resourceGroupName string, options *armnetwork.LoadBalancersClientListOptions,
|
|
|
|
) *runtime.Pager[armnetwork.LoadBalancersClientListResponse] {
|
|
|
|
return runtime.NewPager(runtime.PagingHandler[armnetwork.LoadBalancersClientListResponse]{
|
|
|
|
More: a.pager.moreFunc(),
|
|
|
|
Fetcher: a.pager.fetcherFunc(),
|
|
|
|
})
|
2022-05-24 04:04:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type stubPublicIPAddressesAPI struct {
|
|
|
|
getResponse armnetwork.PublicIPAddressesClientGetResponse
|
|
|
|
getVirtualMachineScaleSetPublicIPAddressResponse armnetwork.PublicIPAddressesClientGetVirtualMachineScaleSetPublicIPAddressResponse
|
|
|
|
getErr error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *stubPublicIPAddressesAPI) Get(ctx context.Context, resourceGroupName string, publicIPAddressName string,
|
|
|
|
options *armnetwork.PublicIPAddressesClientGetOptions,
|
|
|
|
) (armnetwork.PublicIPAddressesClientGetResponse, error) {
|
|
|
|
return a.getResponse, a.getErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *stubPublicIPAddressesAPI) GetVirtualMachineScaleSetPublicIPAddress(ctx context.Context, resourceGroupName string, virtualMachineScaleSetName string,
|
|
|
|
virtualmachineIndex string, networkInterfaceName string, IPConfigurationName string, publicIPAddressName string,
|
|
|
|
options *armnetwork.PublicIPAddressesClientGetVirtualMachineScaleSetPublicIPAddressOptions,
|
|
|
|
) (armnetwork.PublicIPAddressesClientGetVirtualMachineScaleSetPublicIPAddressResponse, error) {
|
|
|
|
return a.getVirtualMachineScaleSetPublicIPAddressResponse, a.getErr
|
|
|
|
}
|
2022-07-27 16:02:33 -04:00
|
|
|
|
|
|
|
type stubVirtualMachineScaleSetVMPager struct {
|
|
|
|
list []armcomputev2.VirtualMachineScaleSetVM
|
|
|
|
fetchErr error
|
|
|
|
more bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *stubVirtualMachineScaleSetVMPager) moreFunc() func(armcomputev2.VirtualMachineScaleSetVMsClientListResponse) bool {
|
|
|
|
return func(armcomputev2.VirtualMachineScaleSetVMsClientListResponse) bool {
|
|
|
|
return p.more
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *stubVirtualMachineScaleSetVMPager) fetcherFunc() func(context.Context, *armcomputev2.VirtualMachineScaleSetVMsClientListResponse) (armcomputev2.VirtualMachineScaleSetVMsClientListResponse, error) {
|
|
|
|
return func(context.Context, *armcomputev2.VirtualMachineScaleSetVMsClientListResponse) (armcomputev2.VirtualMachineScaleSetVMsClientListResponse, error) {
|
|
|
|
page := make([]*armcomputev2.VirtualMachineScaleSetVM, len(p.list))
|
|
|
|
for i := range p.list {
|
|
|
|
page[i] = &p.list[i]
|
|
|
|
}
|
|
|
|
return armcomputev2.VirtualMachineScaleSetVMsClientListResponse{
|
|
|
|
VirtualMachineScaleSetVMListResult: armcomputev2.VirtualMachineScaleSetVMListResult{
|
|
|
|
Value: page,
|
|
|
|
},
|
|
|
|
}, p.fetchErr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type stubLoadBalancersClientListPager struct {
|
|
|
|
list []armnetwork.LoadBalancer
|
|
|
|
fetchErr error
|
|
|
|
more bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *stubLoadBalancersClientListPager) moreFunc() func(armnetwork.LoadBalancersClientListResponse) bool {
|
|
|
|
return func(armnetwork.LoadBalancersClientListResponse) bool {
|
|
|
|
return p.more
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *stubLoadBalancersClientListPager) fetcherFunc() func(context.Context, *armnetwork.LoadBalancersClientListResponse) (armnetwork.LoadBalancersClientListResponse, error) {
|
|
|
|
return func(context.Context, *armnetwork.LoadBalancersClientListResponse) (armnetwork.LoadBalancersClientListResponse, error) {
|
|
|
|
page := make([]*armnetwork.LoadBalancer, len(p.list))
|
|
|
|
for i := range p.list {
|
|
|
|
page[i] = &p.list[i]
|
|
|
|
}
|
|
|
|
return armnetwork.LoadBalancersClientListResponse{
|
|
|
|
LoadBalancerListResult: armnetwork.LoadBalancerListResult{
|
|
|
|
Value: page,
|
|
|
|
},
|
|
|
|
}, p.fetchErr
|
|
|
|
}
|
|
|
|
}
|