Debian Codegraph @

provider/azure/azure_discover_test.go

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