1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
package azure_test
import (
"log"
"os"
"testing"
discover "github.com/hashicorp/go-discover"
"github.com/hashicorp/go-discover/provider/azure"
)
var _ discover.Provider = (*azure.Provider)(nil)
var _ discover.ProviderWithUserAgent = (*azure.Provider)(nil)
func TestTagAddrsWithEnv(t *testing.T) {
args := discover.Config{
"provider": "azure",
"tag_name": "consul",
"tag_value": "server",
}
if os.Getenv("ARM_SUBSCRIPTION_ID") == "" || os.Getenv("ARM_CLIENT_ID") == "" || os.Getenv("ARM_CLIENT_SECRET") == "" || os.Getenv("ARM_TENANT_ID") == "" {
t.Skip("Azure Enviornmental credentials missing")
}
if args["environment"] == "" {
t.Log("Environments other than Public not supported at the moment")
}
p := &azure.Provider{}
l := log.New(os.Stderr, "", log.LstdFlags)
addrs, err := p.Addrs(args, l)
if err != nil {
t.Fatal(err)
}
if len(addrs) != 2 {
t.Fatalf("bad: %v", addrs)
}
}
func TestTagAddrs(t *testing.T) {
args := discover.Config{
"provider": "azure",
"tag_name": "consul",
"tag_value": "server",
"subscription_id": os.Getenv("ARM_SUBSCRIPTION_ID"),
"tenant_id": os.Getenv("ARM_TENANT_ID"),
"client_id": os.Getenv("ARM_CLIENT_ID"),
"secret_access_key": os.Getenv("ARM_CLIENT_SECRET"),
"environment": os.Getenv("ARM_ENVIRONMENT"),
}
if args["subscription_id"] == "" || args["client_id"] == "" || args["secret_access_key"] == "" || args["tenant_id"] == "" {
t.Skip("Azure credentials missing")
}
if args["environment"] == "" {
t.Log("Environments other than Public not supported at the moment")
}
p := &azure.Provider{}
l := log.New(os.Stderr, "", log.LstdFlags)
addrs, err := p.Addrs(args, l)
if err != nil {
t.Fatal(err)
}
if len(addrs) != 2 {
t.Fatalf("bad: %v", addrs)
}
}
func TestVmScaleSetAddrs(t *testing.T) {
args := discover.Config{
"provider": "azure",
"resource_group": "go-discover-azure-vmss-dev",
"vm_scale_set": "go-discover-azure-vmss-01-scale-set",
"subscription_id": os.Getenv("ARM_SUBSCRIPTION_ID"),
"tenant_id": os.Getenv("ARM_TENANT_ID"),
"client_id": os.Getenv("ARM_CLIENT_ID"),
"secret_access_key": os.Getenv("ARM_CLIENT_SECRET"),
"environment": os.Getenv("ARM_ENVIRONMENT"),
}
if args["subscription_id"] == "" || args["client_id"] == "" || args["secret_access_key"] == "" || args["tenant_id"] == "" {
t.Skip("Azure credentials missing")
}
if args["environment"] == "" {
t.Log("Environments other than Public not supported at the moment")
}
p := &azure.Provider{}
l := log.New(os.Stderr, "", log.LstdFlags)
addrs, err := p.Addrs(args, l)
if err != nil {
t.Fatal(err)
}
if len(addrs) != 3 {
t.Fatalf("bad: %v", addrs)
}
}
|