Skip to content

Commit

Permalink
Added obo token resource unit and acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nfx committed Jul 21, 2021
1 parent aa12c08 commit 8ffa89a
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 0 deletions.
34 changes: 34 additions & 0 deletions identity/acceptance/obo_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package acceptance

import (
"github.com/databrickslabs/terraform-provider-databricks/internal/acceptance"

"testing"
)

func TestAwsAccOboTokenResource(t *testing.T) {
acceptance.Test(t, []acceptance.Step{
{
Template: `
resource "databricks_service_principal" "this" {
display_name = "tf-{var.RANDOM}"
}
data "databricks_group" "admins" {
display_name = "admins"
}
resource "databricks_group_member" "this" {
group_id = data.databricks_group.admins.id
member_id = databricks_service_principal.this.id
}
resource "databricks_obo_token" "this" {
depends_on = [databricks_group_member.this]
application_id = databricks_service_principal.this.application_id
comment = "PAT on behalf of ${databricks_service_principal.this.display_name}"
lifetime_seconds = 3600
}`,
},
})
}
118 changes: 118 additions & 0 deletions identity/resource_obo_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,121 @@ func TestAwsAccOboFlow(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, r.TokenInfo.TokenID, oboToken.TokenInfo.TokenID)
}

func TestResourceOboTokenRead(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.0/token-management/tokens/abc",

Response: TokenResponse{
TokenInfo: &TokenInfo{
Comment: "Hello, world!",
},
},
},
},
Resource: ResourceOboToken(),
Read: true,
New: true,
ID: "abc",
}.Apply(t)
assert.NoError(t, err, err)
assert.Equal(t, "abc", d.Id(), "Id should not be empty")
assert.Equal(t, "Hello, world!", d.Get("comment"))
}

func TestResourceOboTokenRead_Error(t *testing.T) {
qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.0/token-management/tokens/abc",
Status: 500,
Response: common.APIError{
Message: "nope",
},
},
},
Resource: ResourceOboToken(),
Read: true,
New: true,
ID: "abc",
}.ExpectError(t, "nope")
}

func TestResourceOboTokenCreate_Error(t *testing.T) {
qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "POST",
Resource: "/api/2.0/token-management/on-behalf-of/tokens",
Status: 500,
Response: common.APIError{
Message: "nope",
},
},
},
Resource: ResourceOboToken(),
Create: true,
New: true,
}.ExpectError(t, "nope")
}

func TestResourceOboTokenCreate(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "POST",
Resource: "/api/2.0/token-management/on-behalf-of/tokens",
ExpectedRequest: OboToken{
ApplicationID: "abc",
LifetimeSeconds: 60,
Comment: "e",
},
Response: TokenResponse{
TokenValue: "s#Cr3t!11",
TokenInfo: &TokenInfo{
TokenID: "bcd",
},
},
},
{
Method: "GET",
Resource: "/api/2.0/token-management/tokens/bcd",
Response: TokenResponse{
TokenInfo: &TokenInfo{
Comment: "Hello, world!",
},
},
},
},
Resource: ResourceOboToken(),
Create: true,
HCL: `
application_id = "abc"
comment = "e"
lifetime_seconds = 60
`,
New: true,
}.Apply(t)
assert.NoError(t, err, err)
assert.Equal(t, "bcd", d.Id(), "Id should not be empty")
assert.Equal(t, "Hello, world!", d.Get("comment"))
}

func TestResourceOboTokenDelete(t *testing.T) {
qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "DELETE",
Resource: "/api/2.0/token-management/tokens/abc",
},
},
Resource: ResourceOboToken(),
Delete: true,
New: true,
ID: "abc",
}.ApplyNoError(t)
}

0 comments on commit 8ffa89a

Please sign in to comment.