|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +package provider |
| 5 | + |
| 6 | +import ( |
| 7 | + "regexp" |
| 8 | + "testing" |
| 9 | + |
| 10 | + "github.com/hashicorp/boundary/testing/controller" |
| 11 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 12 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 13 | +) |
| 14 | + |
| 15 | +var ( |
| 16 | + fooAliasesDataMissingScope = ` |
| 17 | +data "boundary_aliases" "foo" {} |
| 18 | +` |
| 19 | + |
| 20 | + fooAliasesData = ` |
| 21 | +data "boundary_aliases" "foo" { |
| 22 | + depends_on = [boundary_alias_target.example] |
| 23 | + scope_id = boundary_alias_target.example.scope_id |
| 24 | +} |
| 25 | +` |
| 26 | +) |
| 27 | + |
| 28 | +func TestAccDataSourceAliases(t *testing.T) { |
| 29 | + tc := controller.NewTestController(t, tcConfig...) |
| 30 | + defer tc.Shutdown() |
| 31 | + url := tc.ApiAddrs()[0] |
| 32 | + |
| 33 | + res := targetAliasResource(targetAliasName, targetAliasDesc, targetAliasValue) |
| 34 | + |
| 35 | + var provider *schema.Provider |
| 36 | + resource.Test(t, resource.TestCase{ |
| 37 | + ProviderFactories: providerFactories(&provider), |
| 38 | + Steps: []resource.TestStep{ |
| 39 | + { |
| 40 | + Config: testConfig(url, fooAliasesDataMissingScope), |
| 41 | + ExpectError: regexp.MustCompile(""), |
| 42 | + }, |
| 43 | + { |
| 44 | + Config: testConfig(url, fooOrg, firstProjectFoo, fooBarTarget, res, fooAliasesData), |
| 45 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 46 | + resource.TestCheckResourceAttr("data.boundary_aliases.foo", "items.#", "1"), |
| 47 | + // resource.TestCheckResourceAttr("data.boundary_users.foo", "items.0.%", "15"), |
| 48 | + // resource.TestCheckResourceAttr("data.boundary_users.foo", "items.0.account_ids.#", "0"), |
| 49 | + // resource.TestCheckResourceAttr("data.boundary_users.foo", "items.0.accounts.#", "0"), |
| 50 | + // resource.TestCheckResourceAttr("data.boundary_users.foo", "items.0.authorized_actions.#", "8"), |
| 51 | + // resource.TestCheckResourceAttrSet("data.boundary_users.foo", "items.0.created_time"), |
| 52 | + // resource.TestCheckResourceAttr("data.boundary_users.foo", "items.0.description", "bar"), |
| 53 | + // resource.TestCheckResourceAttr("data.boundary_users.foo", "items.0.email", ""), |
| 54 | + // resource.TestCheckResourceAttr("data.boundary_users.foo", "items.0.full_name", ""), |
| 55 | + // resource.TestCheckResourceAttrSet("data.boundary_users.foo", "items.0.id"), |
| 56 | + // resource.TestCheckResourceAttr("data.boundary_users.foo", "items.0.login_name", ""), |
| 57 | + // resource.TestCheckResourceAttr("data.boundary_users.foo", "items.0.name", "test"), |
| 58 | + // resource.TestCheckResourceAttr("data.boundary_users.foo", "items.0.primary_account_id", ""), |
| 59 | + // resource.TestCheckResourceAttr("data.boundary_users.foo", "items.0.scope.#", "1"), |
| 60 | + // resource.TestCheckResourceAttr("data.boundary_users.foo", "items.0.scope.0.%", "5"), |
| 61 | + // resource.TestCheckResourceAttr("data.boundary_users.foo", "items.0.scope.0.description", ""), |
| 62 | + // resource.TestCheckResourceAttrSet("data.boundary_users.foo", "items.0.scope.0.id"), |
| 63 | + // resource.TestCheckResourceAttr("data.boundary_users.foo", "items.0.scope.0.name", "org1"), |
| 64 | + // resource.TestCheckResourceAttr("data.boundary_users.foo", "items.0.scope.0.parent_scope_id", "global"), |
| 65 | + // resource.TestCheckResourceAttr("data.boundary_users.foo", "items.0.scope.0.type", "org"), |
| 66 | + // resource.TestCheckResourceAttrSet("data.boundary_users.foo", "items.0.scope_id"), |
| 67 | + // resource.TestCheckResourceAttrSet("data.boundary_users.foo", "items.0.updated_time"), |
| 68 | + // resource.TestCheckResourceAttr("data.boundary_users.foo", "items.0.version", "1"), |
| 69 | + // resource.TestCheckResourceAttrSet("data.boundary_users.foo", "scope_id"), |
| 70 | + ), |
| 71 | + }, |
| 72 | + }, |
| 73 | + }) |
| 74 | +} |
0 commit comments