Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #148 from alexkappa/fix-client-is_first_party
Browse files Browse the repository at this point in the history
Fix client is_first_party if set to zero value
  • Loading branch information
alexkappa authored Dec 12, 2019
2 parents ba80a18 + e7bee44 commit 2013ce5
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 10 deletions.
6 changes: 3 additions & 3 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ resource/auth0_tenant:
- '**/*tenant.go'
- '**/*tenant_test.go'

resource/auth0_user:
- '**/*user.go'
- '**/*user_test.go'
resource_data:
- '**/resource_data.go'
- '**/resource_data_test.go'
6 changes: 6 additions & 0 deletions auth0/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package auth0

import (
"os"
"testing"

"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"gopkg.in/auth0.v2/management"
)
Expand Down Expand Up @@ -55,6 +57,10 @@ func Provider() *schema.Provider {
}
}

func TestMain(m *testing.M) {
resource.TestMain(m)
}

func configure(data *schema.ResourceData) (interface{}, error) {

domain := data.Get("domain").(string)
Expand Down
1 change: 1 addition & 0 deletions auth0/resource_auth0_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func newClient() *schema.Resource {
"oidc_conformant": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"callbacks": {
Type: schema.TypeList,
Expand Down
51 changes: 51 additions & 0 deletions auth0/resource_auth0_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,54 @@ resource "auth0_client" "my_client" {
}
}
`

func TestAccClientZeroValueCheck(t *testing.T) {

resource.Test(t, resource.TestCase{
Providers: map[string]terraform.ResourceProvider{
"auth0": Provider(),
},
Steps: []resource.TestStep{
{
Config: testAccClientConfig_create,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_client.my_client", "name", "Application - Acceptance Test - Zero Value Check"),
resource.TestCheckResourceAttr("auth0_client.my_client", "is_first_party", "false"),
),
},
{
Config: testAccClientConfig_update,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_client.my_client", "is_first_party", "true"),
),
},
{
Config: testAccClientConfig_update_again,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_client.my_client", "is_first_party", "false"),
),
},
},
})
}

const testAccClientConfig_create = `
resource "auth0_client" "my_client" {
name = "Application - Acceptance Test - Zero Value Check"
is_first_party = false
}
`

const testAccClientConfig_update = `
resource "auth0_client" "my_client" {
name = "Application - Acceptance Test - Zero Value Check"
is_first_party = true
}
`

const testAccClientConfig_update_again = `
resource "auth0_client" "my_client" {
name = "Application - Acceptance Test - Zero Value Check"
is_first_party = false
}
`
22 changes: 15 additions & 7 deletions auth0/resource_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
// methods defined below.
type Data interface {

// IsNewResource reports whether or not the resource is seen for the first
// time. If so, checks for change won't be carried out.
IsNewResource() bool

// HasChange reports whether or not the given key has been changed.
HasChange(key string) bool

Expand All @@ -25,6 +29,10 @@ type Data interface {
// accessor methods defined below.
type MapData map[string]interface{}

func (md MapData) IsNewResource() bool {
return false
}

func (md MapData) HasChange(key string) bool {
_, ok := md[key]
return ok
Expand All @@ -48,7 +56,7 @@ var _ Data = (*schema.ResourceData)(nil)
// String accesses the value held by key and type asserts it to a pointer to a
// string.
func String(d Data, key string) (s *string) {
if d.HasChange(key) {
if d.IsNewResource() || d.HasChange(key) {
v, ok := d.GetOkExists(key)
if ok {
s = auth0.String(v.(string))
Expand All @@ -60,7 +68,7 @@ func String(d Data, key string) (s *string) {
// Int accesses the value held by key and type asserts it to a pointer to a
// int.
func Int(d Data, key string) (i *int) {
if d.HasChange(key) {
if d.IsNewResource() || d.HasChange(key) {
v, ok := d.GetOkExists(key)
if ok {
i = auth0.Int(v.(int))
Expand All @@ -72,7 +80,7 @@ func Int(d Data, key string) (i *int) {
// Bool accesses the value held by key and type asserts it to a pointer to a
// bool.
func Bool(d Data, key string) (b *bool) {
if d.HasChange(key) {
if d.IsNewResource() || d.HasChange(key) {
v, ok := d.GetOkExists(key)
if ok {
b = auth0.Bool(v.(bool))
Expand All @@ -83,7 +91,7 @@ func Bool(d Data, key string) (b *bool) {

// Slice accesses the value held by key and type asserts it to a slice.
func Slice(d Data, key string) (s []interface{}) {
if d.HasChange(key) {
if d.IsNewResource() || d.HasChange(key) {
v, ok := d.GetOkExists(key)
if ok {
s = v.([]interface{})
Expand All @@ -94,7 +102,7 @@ func Slice(d Data, key string) (s []interface{}) {

// Map accesses the value held by key and type asserts it to a map.
func Map(d Data, key string) (m map[string]interface{}) {
if d.HasChange(key) {
if d.IsNewResource() || d.HasChange(key) {
v, ok := d.GetOkExists(key)
if ok {
m = v.(map[string]interface{})
Expand All @@ -109,7 +117,7 @@ func Map(d Data, key string) (m map[string]interface{}) {
// The iterator can go over all the items in the list or just the first one,
// which is a common use case for defining nested schemas in Terraform.
func List(d Data, key string) *iterator {
if d.HasChange(key) {
if d.IsNewResource() || d.HasChange(key) {
v, ok := d.GetOkExists(key)
if ok {
return &iterator{v.([]interface{})}
Expand All @@ -121,7 +129,7 @@ func List(d Data, key string) *iterator {
// Set accesses the value held by key, type asserts it to a set and returns an
// iterator able to go over the items of the list.
func Set(d Data, key string) *iterator {
if d.HasChange(key) {
if d.IsNewResource() || d.HasChange(key) {
v, ok := d.GetOkExists(key)
if ok {
if s, ok := v.(*schema.Set); ok {
Expand Down

0 comments on commit 2013ce5

Please sign in to comment.