-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f8519f
commit 6350b6d
Showing
5 changed files
with
177 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 |
---|---|---|
|
@@ -23,6 +23,7 @@ website/node_modules | |
*.iml | ||
*.test | ||
*.iml | ||
.vscode/ | ||
|
||
website/vendor | ||
|
||
|
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
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,99 @@ | ||
package digitalocean | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/digitalocean/godo" | ||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccDigitalOceanKubernetes_Basic(t *testing.T) { | ||
rName := acctest.RandString(10) | ||
var k8s godo.KubernetesCluster | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckDigitalOceanKubernetesDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDigitalOceanKubernetesConfigBasic(rName), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
testAccCheckDigitalOceanKubernetesExists("digitalocean_kubernetes_cluster.foobar", &k8s), | ||
resource.TestCheckResourceAttr("digitalocean_kubernetes_cluster.foobar", "node_pool.#", "1"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDigitalOceanKubernetesConfigBasic(rName string) string { | ||
return fmt.Sprintf(` | ||
resource "digitalocean_kubernetes_cluster" "foobar" { | ||
name = "%s" | ||
region = "lon1" | ||
version = "1.12.1-do.2" | ||
tags = ["foo","bar"] | ||
node_pool { | ||
name = "default" | ||
size = "s-1vcpu-2gb" | ||
count = 3 | ||
tags = ["one","two"] | ||
} | ||
} | ||
`, rName) | ||
} | ||
|
||
func testAccCheckDigitalOceanKubernetesDestroy(s *terraform.State) error { | ||
client := testAccProvider.Meta().(*godo.Client) | ||
|
||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "digitalocean_kubernetes_cluster" { | ||
continue | ||
} | ||
|
||
// Try to find the firewall | ||
_, _, err := client.Kubernetes.Get(context.Background(), rs.Primary.ID) | ||
|
||
if err == nil { | ||
return fmt.Errorf("K8s Cluster still exists") | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func testAccCheckDigitalOceanKubernetesExists(n string, cluster *godo.KubernetesCluster) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
|
||
if !ok { | ||
return fmt.Errorf("Not found: %s", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("No Record ID is set") | ||
} | ||
|
||
client := testAccProvider.Meta().(*godo.Client) | ||
|
||
foundCluster, _, err := client.Kubernetes.Get(context.Background(), rs.Primary.ID) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
if foundCluster.ID != rs.Primary.ID { | ||
return fmt.Errorf("Record not found") | ||
} | ||
|
||
*cluster = *foundCluster | ||
|
||
return 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