Skip to content

Commit

Permalink
add muxed provider acc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fairclothjm committed Dec 5, 2023
1 parent fc3d003 commit 852ea9a
Showing 1 changed file with 36 additions and 18 deletions.
54 changes: 36 additions & 18 deletions vault/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
package vault

import (
"context"
"fmt"
"io/ioutil"
"os"
"path"
"sync"
"testing"

"github.com/hashicorp/terraform-plugin-go/tfprotov5"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -108,16 +110,27 @@ const tokenHelperScript = `#!/usr/bin/env bash
echo "helper-token"
`

func TestAccAuthLoginProviderConfigure(t *testing.T) {
rootProvider := Provider()
rootProviderResource := &schema.Resource{
Schema: rootProvider.Schema,
func testAccProtoV5ProviderFactories(ctx context.Context, t *testing.T, v **schema.Provider) map[string]func() (tfprotov5.ProviderServer, error) {
providerServerFactory, p, err := ProtoV5ProviderServerFactory(ctx)
if err != nil {
t.Fatal(err)
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testutil.TestAccPreCheck(t) },
Providers: map[string]*schema.Provider{
"vault": rootProvider,

providerServer := providerServerFactory()
*v = p.SchemaProvider()

return map[string]func() (tfprotov5.ProviderServer, error){
providerName: func() (tfprotov5.ProviderServer, error) {
return providerServer, nil
},
}
}

func TestAccAuthLoginProviderConfigure(t *testing.T) {
var p *schema.Provider
resource.Test(t, resource.TestCase{
PreCheck: func() { testutil.TestAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(context.Background(), t, &p),
Steps: []resource.TestStep{
{
Config: testResourceApproleConfig_basic(),
Expand All @@ -126,21 +139,21 @@ func TestAccAuthLoginProviderConfigure(t *testing.T) {
},
})

rootProviderResource := &schema.Resource{
Schema: p.Schema,
}
rootProviderData := rootProviderResource.TestResourceData()
if _, err := provider.NewProviderMeta(rootProviderData); err != nil {
t.Fatal(err)
}
}

func TestTokenReadProviderConfigureWithHeaders(t *testing.T) {
rootProvider := Provider()
var p *schema.Provider

rootProviderResource := &schema.Resource{
Schema: rootProvider.Schema,
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testutil.TestAccPreCheck(t) },
ProviderFactories: providerFactories,
PreCheck: func() { testutil.TestAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(context.Background(), t, &p),
Steps: []resource.TestStep{
{
Config: testHeaderConfig("auth", "123"),
Expand All @@ -149,6 +162,9 @@ func TestTokenReadProviderConfigureWithHeaders(t *testing.T) {
},
})

rootProviderResource := &schema.Resource{
Schema: p.Schema,
}
rootProviderData := rootProviderResource.TestResourceData()
if _, err := provider.NewProviderMeta(rootProviderData); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -548,11 +564,12 @@ func TestAccTokenName(t *testing.T) {
},
}

var p *schema.Provider
for _, test := range tests {
t.Run(test.WantTokenName, func(t *testing.T) {
resource.Test(t, resource.TestCase{
ProviderFactories: providerFactories,
PreCheck: func() { testutil.TestAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(context.Background(), t, &p),
PreCheck: func() { testutil.TestAccPreCheck(t) },
Steps: []resource.TestStep{
{
PreConfig: func() {
Expand Down Expand Up @@ -611,11 +628,12 @@ func TestAccChildToken(t *testing.T) {
},
}

var p *schema.Provider
for name, test := range tests {
t.Run(name, func(t *testing.T) {
resource.Test(t, resource.TestCase{
ProviderFactories: providerFactories,
PreCheck: func() { testutil.TestAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories(context.Background(), t, &p),
PreCheck: func() { testutil.TestAccPreCheck(t) },
Steps: []resource.TestStep{
{
Config: testProviderConfig(test.useChildTokenSchema,
Expand Down

0 comments on commit 852ea9a

Please sign in to comment.