Files
virtual-kubelet/providers/azure/client/network/client_test.go
Brian Goff 25e454d18f Add API client for Azure custom vnet (#271)
* Update vendor for azure vent support

* Add support for Azure custom vnets.

Use pointers intead of values. This allows the client to pass back
returned data from Azure.
2018-09-07 18:46:49 -07:00

46 lines
1.2 KiB
Go

package network
import (
"context"
"sync"
"testing"
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-05-01/network"
"github.com/Azure/go-autorest/autorest/azure/auth"
)
var vnetAuthOnce sync.Once
var azAuth autorest.Authorizer
func ensureVnet(t *testing.T, name string) {
vnetAuthOnce.Do(func() {
var err error
azAuth, err = auth.NewClientCredentialsConfig(testAuth.ClientID, testAuth.ClientSecret, testAuth.TenantID).Authorizer()
if err != nil {
t.Fatalf("error setting up client auth for vnet create: %v", err)
}
})
client := network.NewVirtualNetworksClient(testAuth.SubscriptionID)
client.Authorizer = azAuth
prefixes := []string{"10.0.0.0/24"}
result, err := client.CreateOrUpdate(context.Background(), resourceGroup, name, network.VirtualNetwork{
Name: &name,
Location: &location,
VirtualNetworkPropertiesFormat: &network.VirtualNetworkPropertiesFormat{
AddressSpace: &network.AddressSpace{
AddressPrefixes: &prefixes,
},
},
})
if err != nil {
t.Fatal(err)
}
if err := result.WaitForCompletion(context.Background(), client.Client); err != nil {
t.Fatal(err)
}
}