mirror of
https://github.com/ysoftdevs/terraform-provider-bitbucketserver.git
synced 2026-03-31 14:33:12 +02:00
Added bitbucketserver_user resource; updated tests to create users on the fly
This commit is contained in:
55
bitbucket/resource_user_test.go
Normal file
55
bitbucket/resource_user_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package bitbucket
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
func TestAccBitbucketUser(t *testing.T) {
|
||||
userRand := fmt.Sprintf("%v", rand.New(rand.NewSource(time.Now().UnixNano())).Int())
|
||||
testAccBitbucketUserConfig := fmt.Sprintf(`
|
||||
resource "bitbucketserver_user" "test" {
|
||||
name = "admin%v"
|
||||
display_name = "Admin %v"
|
||||
email_address = "admin%v@example.com"
|
||||
}
|
||||
`, userRand, userRand, userRand)
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckBitbucketUserDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccBitbucketUserConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttr("bitbucketserver_user.test", "name", "admin"+userRand),
|
||||
resource.TestCheckResourceAttr("bitbucketserver_user.test", "display_name", "Admin "+userRand),
|
||||
resource.TestCheckResourceAttr("bitbucketserver_user.test", "email_address", "admin"+userRand+"@example.com"),
|
||||
resource.TestCheckResourceAttrSet("bitbucketserver_user.test", "initial_password"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccCheckBitbucketUserDestroy(s *terraform.State) error {
|
||||
client := testAccProvider.Meta().(*BitbucketClient)
|
||||
rs, ok := s.RootModule().Resources["bitbucketserver_user.test"]
|
||||
if !ok {
|
||||
return fmt.Errorf("not found %s", "bitbucketserver_user.test")
|
||||
}
|
||||
|
||||
response, _ := client.Get(fmt.Sprintf("/rest/api/1.0/users/%s", rs.Primary.Attributes["name"]))
|
||||
|
||||
if response.StatusCode != 404 {
|
||||
return fmt.Errorf("user still exists")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user