|
1 | 1 | package gitlab
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "regexp" |
| 4 | + "fmt" |
5 | 5 | "testing"
|
6 | 6 |
|
| 7 | + "github.com/hashicorp/terraform/helper/acctest" |
7 | 8 | "github.com/hashicorp/terraform/helper/resource"
|
8 | 9 | )
|
9 | 10 |
|
10 | 11 | func TestAccDataSourceGitlabUsers_basic(t *testing.T) {
|
| 12 | + rInt := acctest.RandInt() |
| 13 | + rInt2 := acctest.RandInt() |
| 14 | + user2 := fmt. Sprintf( "user%[email protected]", rInt2) |
| 15 | + |
11 | 16 | resource.Test(t, resource.TestCase{
|
12 | 17 | PreCheck: func() { testAccPreCheck(t) },
|
13 | 18 | Providers: testAccProviders,
|
14 | 19 | Steps: []resource.TestStep{
|
15 |
| - resource.TestStep{ |
16 |
| - Config: testAccComputeLbIpRangesConfig, |
| 20 | + { |
| 21 | + Config: testAccDataSourceGitlabUsersConfig(rInt, rInt2), |
| 22 | + Check: resource.ComposeTestCheckFunc( |
| 23 | + resource.TestCheckResourceAttr("gitlab_user.foo", "name", "footest1"), |
| 24 | + resource.TestCheckResourceAttr("gitlab_user.foo2", "name", "footest2"), |
| 25 | + ), |
| 26 | + }, |
| 27 | + { |
| 28 | + Config: testAccDataSourceGitlabUsersConfigSort(rInt, rInt2), |
17 | 29 | Check: resource.ComposeTestCheckFunc(
|
18 |
| - resource.TestMatchResourceAttr("data.gitlab_users.test", |
19 |
| - "users.#", regexp.MustCompile("^[1-9]*$"))), |
| 30 | + resource.TestCheckResourceAttr("data.gitlab_users.foo", "users.#", "2"), |
| 31 | + resource.TestCheckResourceAttr("data.gitlab_users.foo", "users.0.email", user2), |
| 32 | + resource.TestCheckResourceAttr("data.gitlab_users.foo", "users.0.projects_limit", "2"), |
| 33 | + ), |
| 34 | + }, |
| 35 | + { |
| 36 | + Config: testAccDataSourceGitlabUsersConfigSearch(rInt, rInt2), |
| 37 | + Check: resource.ComposeTestCheckFunc( |
| 38 | + resource.TestCheckResourceAttr("data.gitlab_users.foo", "users.#", "1"), |
| 39 | + // resource.TestCheckResourceAttr("data.gitlab_users.foo", "users.0.email", user2), |
| 40 | + ), |
20 | 41 | },
|
21 | 42 | },
|
22 | 43 | })
|
23 | 44 | }
|
24 | 45 |
|
25 |
| -const testAccComputeLbIpRangesConfig = ` |
26 |
| -data "gitlab_users" "test" {} |
27 |
| -` |
| 46 | +func testAccDataSourceGitlabUsersConfig(rInt int, rInt2 int) string { |
| 47 | + return fmt.Sprintf(` |
| 48 | +resource "gitlab_user" "foo" { |
| 49 | + name = "footest1" |
| 50 | + username = "listest%d" |
| 51 | + password = "test%dtt" |
| 52 | + |
| 53 | + projects_limit = 3 |
| 54 | +} |
| 55 | +
|
| 56 | +resource "gitlab_user" "foo2" { |
| 57 | + name = "footest2" |
| 58 | + username = "listest%d" |
| 59 | + password = "test%dtt" |
| 60 | + |
| 61 | + projects_limit = 2 |
| 62 | +} |
| 63 | + `, rInt, rInt, rInt, rInt2, rInt2, rInt2) |
| 64 | +} |
| 65 | + |
| 66 | +func testAccDataSourceGitlabUsersConfigSort(rInt int, rInt2 int) string { |
| 67 | + return fmt.Sprintf(` |
| 68 | +resource "gitlab_user" "foo" { |
| 69 | + name = "footest1" |
| 70 | + username = "listest%d" |
| 71 | + password = "test%dtt" |
| 72 | + |
| 73 | + projects_limit = 3 |
| 74 | +} |
| 75 | +
|
| 76 | +resource "gitlab_user" "foo2" { |
| 77 | + name = "footest2" |
| 78 | + username = "listest%d" |
| 79 | + password = "test%dtt" |
| 80 | + |
| 81 | + projects_limit = 2 |
| 82 | +} |
| 83 | +
|
| 84 | +data "gitlab_users" "foo" { |
| 85 | + sort = "desc" |
| 86 | + search = "footest" |
| 87 | + order_by = "name" |
| 88 | +} |
| 89 | + `, rInt, rInt, rInt, rInt2, rInt2, rInt2) |
| 90 | +} |
| 91 | + |
| 92 | +func testAccDataSourceGitlabUsersConfigSearch(rInt int, rInt2 int) string { |
| 93 | + return fmt.Sprintf(` |
| 94 | +resource "gitlab_user" "foo" { |
| 95 | + name = "footest1" |
| 96 | + username = "listest%d" |
| 97 | + password = "test%dtt" |
| 98 | + |
| 99 | + projects_limit = 3 |
| 100 | +} |
| 101 | +
|
| 102 | +resource "gitlab_user" "foo2" { |
| 103 | + name = "footest2" |
| 104 | + username = "listest%d" |
| 105 | + password = "test%dtt" |
| 106 | + |
| 107 | + projects_limit = 2 |
| 108 | +} |
| 109 | +
|
| 110 | +data "gitlab_users" "foo" { |
| 111 | + |
| 112 | +} |
| 113 | + `, rInt, rInt, rInt, rInt2, rInt2, rInt2, rInt2) |
| 114 | +} |
0 commit comments