Skip to content

Commit 96a1622

Browse files
committed
github_user: add acceptance tests
1 parent 5833ffe commit 96a1622

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
}

0 commit comments

Comments
 (0)