Debian Codegraph @

provider/vsphere/vsphere_discover_test.go

raw symbols SCIP
1 package vsphere_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/vsphere"
10 )
11
12 var _ discover.Provider = (*vsphere.Provider)(nil)
13
14 func testPreCheck(t *testing.T) {
15 if v := os.Getenv("VSPHERE_USER"); v == "" {
16 t.Skip("VSPHERE_USER must be set for acceptance tests")
17 }
18
19 if v := os.Getenv("VSPHERE_PASSWORD"); v == "" {
20 t.Skip("VSPHERE_PASSWORD must be set for acceptance tests")
21 }
22
23 if v := os.Getenv("VSPHERE_SERVER"); v == "" {
24 t.Skip("VSPHERE_SERVER must be set for acceptance tests")
25 }
26 }
27
28 func TestAddrs(t *testing.T) {
29 testPreCheck(t)
30
31 args := discover.Config{
32 "provider": "vsphere",
33 "tag_name": "go-discover-test-tag",
34 "category_name": "go-discover-test-category",
35 "host": os.Getenv("VSPHERE_SERVER"),
36 "user": os.Getenv("VSPHERE_USER"),
37 "password": os.Getenv("VSPHERE_PASSWORD"),
38 "insecure_ssl": os.Getenv("VSPHERE_ALLOW_UNVERIFIED_SSL"),
39 "timeout": "20m",
40 }
41
42 l := log.New(os.Stderr, "", log.LstdFlags)
43 p := &vsphere.Provider{}
44 addrs, err := p.Addrs(args, l)
45 if err != nil {
46 t.Fatal(err)
47 }
48
49 actual := map[string]bool{
50 "10.0.0.10": false,
51 "10.0.0.11": false,
52 }
53
54 for _, addr := range addrs {
55 if addr == "10.0.0.10" || addr == "10.0.0.11" {
56 actual[addr] = true
57 }
58 }
59
60 for k, v := range actual {
61 if !v {
62 t.Fatalf("IP address %s is missing from discovery output", k)
63 }
64 }
65 }
66
67 // TestAddrsEnv tests to make sure that we can lean on the environment for
68 // credentials automatically. User credential environment variables are not set
69 // using Setenv, leaving them to be fetched from the environment 100%.
70 func TestAddrsEnv(t *testing.T) {
71 testPreCheck(t)
72
73 args := discover.Config{
74 "provider": "vsphere",
75 "tag_name": "go-discover-test-tag",
76 "category_name": "go-discover-test-category",
77 "timeout": "20m",
78 }
79
80 l := log.New(os.Stderr, "", log.LstdFlags)
81 p := &vsphere.Provider{}
82 addrs, err := p.Addrs(args, l)
83 if err != nil {
84 t.Fatal(err)
85 }
86
87 actual := map[string]bool{
88 "10.0.0.10": false,
89 "10.0.0.11": false,
90 }
91
92 for _, addr := range addrs {
93 if addr == "10.0.0.10" || addr == "10.0.0.11" {
94 actual[addr] = true
95 }
96 }
97
98 for k, v := range actual {
99 if !v {
100 t.Fatalf("IP address %s is missing from discovery output", k)
101 }
102 }
103 }