Skip to content

Commit

Permalink
split the test into vcenter and esxi specific and removed the tabs in…
Browse files Browse the repository at this point in the history
… config
  • Loading branch information
girishramnani-crest committed Aug 11, 2017
1 parent 7e239a1 commit 316e794
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
1 change: 0 additions & 1 deletion vsphere/resource_vsphere_license.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func resourceVSphereLicenseCreate(d *schema.ResourceData, meta interface{}) erro
var err error
switch t := client.ServiceContent.About.ApiType; t {
case "HostAgent":

// Labels are not allowed in ESXi
if len(finalLabels) != 0 {
return errors.New("Labels are not allowed in ESXi")
Expand Down
61 changes: 47 additions & 14 deletions vsphere/resource_vsphere_license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"strconv"
"testing"

"regexp"
Expand Down Expand Up @@ -55,12 +56,13 @@ func TestAccVSphereLicenseInvalid(t *testing.T) {

}

func TestAccVSphereLicenseWithLabels(t *testing.T) {
func TestAccVSphereLicenseWithLabelsOnVCenter(t *testing.T) {

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccVSpherePreLicenseBasicCheck(t)
testAccVspherePreLicenseESXiServerIsNotSetCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
Expand All @@ -69,14 +71,45 @@ func TestAccVSphereLicenseWithLabels(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccVSphereLicenseWithLabelExists("vsphere_license.foo"),
),
// This error will only be thrown when run against an ESXi server.
},
},
})

}

func TestAccVSphereLicenseWithLabelsOnESXiServer(t *testing.T) {

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccVSpherePreLicenseBasicCheck(t)
testAccVspherePreLicenseESXiServerIsSetCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccVSphereLicenseWithLabelConfig(),
// This error will be thrown when ran against an ESXi server.
ExpectError: regexp.MustCompile("Labels are not allowed in ESXi"),
},
},
})

}

func testAccVspherePreLicenseESXiServerIsNotSetCheck(t *testing.T) {
key, err := strconv.ParseBool(os.Getenv("VSPHERE_TEST_ESXI"))
if err == nil && key {
t.Skip("VSPHERE_TEST_ESXI must not be set for this acceptance test")
}
}
func testAccVspherePreLicenseESXiServerIsSetCheck(t *testing.T) {
key, err := strconv.ParseBool(os.Getenv("VSPHERE_TEST_ESXI"))
if err != nil || !key {
t.Skip("VSPHERE_TEST_ESXI must be set to true for this acceptance test")
}
}

func testAccVSphereLicenseInvalidConfig() string {
// quite sure this key cannot be valid
return `resource "vsphere_license" "foo" {
Expand All @@ -86,22 +119,22 @@ func testAccVSphereLicenseInvalidConfig() string {

func testAccVSphereLicenseWithLabelConfig() string {
return fmt.Sprintf(`
resource "vsphere_license" "foo" {
license_key = "%s"
labels {
VpxClientLicenseLabel = "Hello World"
TestTitle = "fooBar"
}
}
`, os.Getenv("VSPHERE_LICENSE"))
resource "vsphere_license" "foo" {
license_key = "%s"
labels {
VpxClientLicenseLabel = "Hello World"
TestTitle = "fooBar"
}
}
`, os.Getenv("VSPHERE_LICENSE"))
}

func testAccVSphereLicenseBasicConfig() string {
return fmt.Sprintf(`
resource "vsphere_license" "foo" {
license_key = "%s"
}
`, os.Getenv("VSPHERE_LICENSE"))
resource "vsphere_license" "foo" {
license_key = "%s"
}
`, os.Getenv("VSPHERE_LICENSE"))
}

func testAccVSphereLicenseDestroy(s *terraform.State) error {
Expand Down

0 comments on commit 316e794

Please sign in to comment.