Skip to content

Commit

Permalink
removed the TODO and changed the testNames for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
girishramnani-crest committed Aug 10, 2017
1 parent 333c9e3 commit b51f522
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
9 changes: 5 additions & 4 deletions vsphere/resource_vsphere_license.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (

var (
// ErrNoSuchKeyFound is an error primarily thrown by the Read method of the resource.
// The error doesnt display the key itself for security reasons.
ErrNoSuchKeyFound = errors.New("The key was not found")
// The error doesn't display the key itself for security reasons.
ErrNoSuchKeyFound = errors.New("The key was not found")
// ErrKeyCannotBeDeleted is an error which occurs when a key that is used by VMs is
// being removed
ErrKeyCannotBeDeleted = errors.New("The key wasn't deleted")
)

Expand Down Expand Up @@ -47,8 +49,7 @@ func resourceVSphereLicense() *schema.Resource {
"key": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true, // TODO: if the key changes then we have to create
// a new one. But this might never call Update method.
ForceNew: true,
},
"value": &schema.Schema{
Type: schema.TypeString,
Expand Down
44 changes: 22 additions & 22 deletions vsphere/resource_vsphere_license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,28 @@ var (
}
)

func TestAccVsphereLicenseBasic(t *testing.T) {
func testAccVSphereLicenseBasic(t *testing.T) {

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccVspherePreLicenseBasicCheck(t)
testAccVSpherePreLicenseBasicCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testAccVsphereLicenseDestroy,
CheckDestroy: testAccVSphereLicenseDestroy,
Steps: []resource.TestStep{
{
Config: testAccVsphereLicenseBasicCreate(),
Config: testAccVSphereLicenseBasicCreate(),
Check: resource.ComposeTestCheckFunc(
testAccVsphereLicenseExists("vsphere_license.foo"),
testAccVSphereLicenseExists("vsphere_license.foo"),
),
},
},
})

}

func TestAccVsphereLicenseInvalid(t *testing.T) {
func testAccVSphereLicenseInvalid(t *testing.T) {

resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand All @@ -66,50 +66,50 @@ func TestAccVsphereLicenseInvalid(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccVsphereLicenseInvalidCreate(),
Config: testAccVSphereLicenseInvalidCreate(),
Check: resource.ComposeTestCheckFunc(
testAccVsphereLicenseNotExists("vsphere_license.foo"),
testAccVSphereLicenseNotExists("vsphere_license.foo"),
),
},
},
})

}

func TestAccVsphereLicenseWithLabels(t *testing.T) {
func testAccVSphereLicenseWithLabels(t *testing.T) {

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccVspherePreLicenseBasicCheck(t)
testAccVSpherePreLicenseBasicCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccVsphereLicenseWithLabelCreate(testAccLabels),
Config: testAccVSphereLicenseWithLabelCreate(testAccLabels),
Check: resource.ComposeTestCheckFunc(
testAccVsphereLicenseWithLabelExists("vsphere_license.foo"),
testAccVSphereLicenseWithLabelExists("vsphere_license.foo"),
),
},
},
})

}

func testAccVsphereLicenseInvalidCreate() string {
func testAccVSphereLicenseInvalidCreate() string {

// quite sure this key cannot be valid
return `resource "vsphere_license" "foo" {
license_key = "00000-00000-00000-00000-12345"
}`
}

func testAccVsphereLicenseWithLabelCreate(labels map[string]string) string {
func testAccVSphereLicenseWithLabelCreate(labels map[string]string) string {

// precheck already checks if this is present or not
key := os.Getenv("VSPHERE_LICENSE")

labelString := labelToStrings(labels)
labelString := labelToString(labels)

return fmt.Sprintf(`resource "vsphere_license" "foo2" {
license_key = "%s"
Expand All @@ -118,7 +118,7 @@ func testAccVsphereLicenseWithLabelCreate(labels map[string]string) string {
}`, key, labelString)
}

func labelToStrings(labels map[string]string) string {
func labelToString(labels map[string]string) string {
val := ""
for key, value := range labels {
val += fmt.Sprintf(`
Expand All @@ -132,7 +132,7 @@ func labelToStrings(labels map[string]string) string {
return val
}

func testAccVsphereLicenseBasicCreate() string {
func testAccVSphereLicenseBasicCreate() string {

// precheck already checks if this is present or not
key := os.Getenv("VSPHERE_LICENSE")
Expand All @@ -144,7 +144,7 @@ func testAccVsphereLicenseBasicCreate() string {

}

func testAccVsphereLicenseDestroy(s *terraform.State) error {
func testAccVSphereLicenseDestroy(s *terraform.State) error {

client := testAccProvider.Meta().(*govmomi.Client)

Expand All @@ -169,7 +169,7 @@ func testAccVsphereLicenseDestroy(s *terraform.State) error {
return nil
}

func testAccVsphereLicenseExists(name string) resource.TestCheckFunc {
func testAccVSphereLicenseExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]

Expand All @@ -188,7 +188,7 @@ func testAccVsphereLicenseExists(name string) resource.TestCheckFunc {
}
}

func testAccVsphereLicenseNotExists(name string) resource.TestCheckFunc {
func testAccVSphereLicenseNotExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
_, ok := s.RootModule().Resources[name]

Expand All @@ -200,13 +200,13 @@ func testAccVsphereLicenseNotExists(name string) resource.TestCheckFunc {
}
}

func testAccVspherePreLicenseBasicCheck(t *testing.T) {
func testAccVSpherePreLicenseBasicCheck(t *testing.T) {
if key := os.Getenv("VSPHERE_LICENSE"); key == "" {
t.Fatal("VSPHERE_LICENSE must be set for acceptance test")
}
}

func testAccVsphereLicenseWithLabelExists(name string) resource.TestCheckFunc {
func testAccVSphereLicenseWithLabelExists(name string) resource.TestCheckFunc {

return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
Expand Down

0 comments on commit b51f522

Please sign in to comment.