github_user: add acceptance tests

This commit is contained in:
Raphaël Pinson 2017-05-17 17:07:15 +02:00
parent 5833ffe0d1
commit 96a1622b03
No known key found for this signature in database
GPG Key ID: DF0A493B74BF771E
1 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,53 @@
package github
import (
"fmt"
"regexp"
"testing"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccGithubUserDataSource_noMatchReturnsError(t *testing.T) {
username := "admin"
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckGithubUserDataSourceConfig(username),
ExpectError: regexp.MustCompile(`Not Found`),
},
},
})
}
func TestAccGithubUserDataSource_existing(t *testing.T) {
username := "raphink"
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckGithubUserDataSourceConfig(username),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("data.github_user.test", "name"),
resource.TestCheckResourceAttr("data.github_user.test", "id", "650430"),
resource.TestCheckResourceAttr("data.github_user.test", "name", "Raphaël Pinson"),
),
},
},
})
}
func testAccCheckGithubUserDataSourceConfig(username string) string {
return fmt.Sprintf(`
data "github_user" "test" {
username = "%s"
}
`, username)
}