github.com/koding/terraform@v0.6.4-0.20170608090606-5d7e0339779d/builtin/providers/github/data_source_github_user_test.go (about) 1 package github 2 3 import ( 4 "fmt" 5 "regexp" 6 "testing" 7 8 "github.com/hashicorp/terraform/helper/resource" 9 ) 10 11 func TestAccGithubUserDataSource_noMatchReturnsError(t *testing.T) { 12 username := "admin" 13 resource.Test(t, resource.TestCase{ 14 PreCheck: func() { 15 testAccPreCheck(t) 16 }, 17 Providers: testAccProviders, 18 Steps: []resource.TestStep{ 19 { 20 Config: testAccCheckGithubUserDataSourceConfig(username), 21 ExpectError: regexp.MustCompile(`Not Found`), 22 }, 23 }, 24 }) 25 } 26 27 func TestAccGithubUserDataSource_existing(t *testing.T) { 28 username := "raphink" 29 resource.Test(t, resource.TestCase{ 30 PreCheck: func() { 31 testAccPreCheck(t) 32 }, 33 Providers: testAccProviders, 34 Steps: []resource.TestStep{ 35 { 36 Config: testAccCheckGithubUserDataSourceConfig(username), 37 Check: resource.ComposeAggregateTestCheckFunc( 38 resource.TestCheckResourceAttrSet("data.github_user.test", "name"), 39 resource.TestCheckResourceAttr("data.github_user.test", "id", "650430"), 40 resource.TestCheckResourceAttr("data.github_user.test", "name", "Raphaƫl Pinson"), 41 ), 42 }, 43 }, 44 }) 45 } 46 47 func testAccCheckGithubUserDataSourceConfig(username string) string { 48 return fmt.Sprintf(` 49 data "github_user" "test" { 50 username = "%s" 51 } 52 `, username) 53 }