forked from digitalocean/terraform-provider-digitalocean
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datasource_digitalocean_ssh_keys_test.go
65 lines (59 loc) · 1.68 KB
/
datasource_digitalocean_ssh_keys_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package digitalocean
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
func TestAccDataSourceDigitalOceanSSHKeys_Basic(t *testing.T) {
keyName1 := fmt.Sprintf("tf-acc-test1-%s", acctest.RandString(10))
pubKey1, err := testAccGenerateDataSourceDigitalOceanSSHKeyPublic()
if err != nil {
t.Fatalf("Unable to generate public key: %v", err)
return
}
keyName2 := fmt.Sprintf("tf-acc-test2-%s", acctest.RandString(10))
pubKey2, err := testAccGenerateDataSourceDigitalOceanSSHKeyPublic()
if err != nil {
t.Fatalf("Unable to generate public key: %v", err)
return
}
resourcesConfig := fmt.Sprintf(`
resource "digitalocean_ssh_key" "foo" {
name = "%s"
public_key = "%s"
}
resource "digitalocean_ssh_key" "bar" {
name = "%s"
public_key = "%s"
}
`, keyName1, pubKey1, keyName2, pubKey2)
datasourceConfig := fmt.Sprintf(`
data "digitalocean_ssh_keys" "result" {
sort {
key = "name"
direction = "asc"
}
}
`)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: resourcesConfig,
},
{
Config: resourcesConfig + datasourceConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.digitalocean_ssh_keys.result", "ssh_keys.#", "2"),
resource.TestCheckResourceAttr("data.digitalocean_ssh_keys.result", "ssh_keys.0.name", keyName1),
resource.TestCheckResourceAttr("data.digitalocean_ssh_keys.result", "ssh_keys.1.name", keyName2),
),
},
{
Config: resourcesConfig,
},
},
})
}