From 96a1622b03ca78b32d57ce5bd08e67e647ffbe24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= Date: Wed, 17 May 2017 17:07:15 +0200 Subject: [PATCH] github_user: add acceptance tests --- .../github/data_source_github_user_test.go | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 builtin/providers/github/data_source_github_user_test.go diff --git a/builtin/providers/github/data_source_github_user_test.go b/builtin/providers/github/data_source_github_user_test.go new file mode 100644 index 0000000000..85202505b6 --- /dev/null +++ b/builtin/providers/github/data_source_github_user_test.go @@ -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) +}