-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_user_test.go
52 lines (46 loc) · 1.41 KB
/
resource_user_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
package jumpcloud
import (
"fmt"
"os"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
func TestAccUser(t *testing.T) {
rName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
// This test simply applys a user with the config from testAccUser
// and checks for the correct username and email in the state
// The resource is destroyed afterwards via the framework
Config: testAccUser(rName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("jumpcloud_user.test_user", "username", rName),
resource.TestCheckResourceAttr("jumpcloud_user.test_user", "email", rName+"@testorg.com"),
),
},
},
})
}
// testAccPreCheck validates the necessary test API keys exist
// in the testing environment
func testAccPreCheck(t *testing.T) {
if v := os.Getenv("JUMPCLOUD_API_KEY"); v == "" {
t.Fatal("JUMPCLOUD_API_KEY= must be set for the acceptance tests")
}
}
func testAccUser(name string) string {
return fmt.Sprintf(`
resource "jumpcloud_user" "test_user" {
username = "%s"
email = "%s@testorg.com"
firstname = "Firstname"
lastname = "Lastname"
enable_mfa = true
}`, name, name,
)
}