Skip to content

Commit

Permalink
fixup client_id_test
Browse files Browse the repository at this point in the history
  • Loading branch information
micahkemp-splunk committed Jun 23, 2022
1 parent 6ad3147 commit ef60820
Showing 1 changed file with 57 additions and 12 deletions.
69 changes: 57 additions & 12 deletions internal/sync/client_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,37 @@ package sync
import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/splunk/go-splunk-client/pkg/client"
)

func Test_clientIdResourceDataHandler(t *testing.T) {
tests := syncResourceTestCases{
{
name: "empty",
sync: NewClientID(&client.ID{}),
checkFunc: checkResourceIdEquals(""),
name: "empty",
sync: NewClientID(&client.ID{}, "name"),
schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
},
},
checkFunc: composeResourceCheckFunc(
checkResourceIdEquals(""),
checkResourceKeyEquals("name", ""),
),
},
{
name: "set",
sync: NewClientID(mustParseID("https://localhost:8089/services/authentication/users/testuser")),
checkFunc: checkResourceIdEquals("https://localhost:8089/services/authentication/users/testuser"),
name: "set",
sync: NewClientID(mustParseID("https://localhost:8089/services/authentication/users/testuser"), "name"),
schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
},
},
checkFunc: composeResourceCheckFunc(
checkResourceIdEquals("https://localhost:8089/services/authentication/users/testuser"),
checkResourceKeyEquals("name", "testuser"),
),
},
}

Expand All @@ -40,22 +57,50 @@ func Test_clientIdResourceDataHandler(t *testing.T) {
func Test_clientIdObjectValueHandler(t *testing.T) {
tests := syncObjectTestCases{
{
name: "empty",
sync: NewClientID(&client.ID{}),
name: "empty",
sync: NewClientID(&client.ID{}, "name"),
schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
},
},
checkFunc: checkGetObjectEquality(&client.ID{}),
},
{
name: "invalid resource Id",
prepFunc: withId("invalid"),
sync: NewClientID(&client.ID{}),
sync: NewClientID(&client.ID{}, "name"),
schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
},
},
// clientId.SyncObject doesn't actually return any errors, as invalid URLs
// are assumed to be due to migration from the legacy client.
checkFunc: checkGetObjectEquality(&client.ID{}),
},
{
name: "valid resource Id",
prepFunc: withId("https://localhost:8089/services/authentication/users/testuser"),
sync: NewClientID(&client.ID{}),
name: "valid resource name",
sync: NewClientID(&client.ID{}, "name"),
schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
},
},
schemaValues: map[string]interface{}{
"name": "valid_name",
},
checkFunc: checkGetObjectEquality(&client.ID{Title: "valid_name"}),
},
{
name: "valid resource Id",
prepFunc: withId("https://localhost:8089/services/authentication/users/testuser"),
sync: NewClientID(&client.ID{}, "name"),
schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
},
},
checkFunc: checkGetObjectEquality(mustParseID("https://localhost:8089/services/authentication/users/testuser")),
},
}
Expand Down

0 comments on commit ef60820

Please sign in to comment.