-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
r/host_virtual_switch: Move test check variable gathering to a helper
This will actually help when I refactor #139, which actually has multiple check calls fetching these kinds of variables.
- Loading branch information
1 parent
5cf0908
commit b55ef8d
Showing
3 changed files
with
48 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package vsphere | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform/terraform" | ||
"github.com/vmware/govmomi" | ||
) | ||
|
||
// testCheckVariables bundles common variables needed by various test checkers. | ||
type testCheckVariables struct { | ||
// A client for various operations. | ||
client *govmomi.Client | ||
|
||
// The subject resource's ID. | ||
resourceID string | ||
|
||
// The ESXi host that a various API call is directed at. | ||
esxiHost string | ||
|
||
// The datacenter that a various API call is directed at. | ||
datacenter string | ||
|
||
// A timeout to pass to various context creation calls. | ||
timeout time.Duration | ||
} | ||
|
||
func testClientVariablesForResource(s *terraform.State, addr string) (testCheckVariables, error) { | ||
rs, ok := s.RootModule().Resources[addr] | ||
if !ok { | ||
return testCheckVariables{}, fmt.Errorf("%s not found in state", addr) | ||
} | ||
|
||
return testCheckVariables{ | ||
client: testAccProvider.Meta().(*govmomi.Client), | ||
resourceID: rs.Primary.ID, | ||
esxiHost: os.Getenv("VSPHERE_ESXI_HOST"), | ||
datacenter: os.Getenv("VSPHERE_DATACENTER"), | ||
timeout: time.Minute * 5, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters