Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic due to flag redefined: sweep #155

Closed
NeilW opened this issue Jul 27, 2023 · 3 comments
Closed

Panic due to flag redefined: sweep #155

NeilW opened this issue Jul 27, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@NeilW
Copy link

NeilW commented Jul 27, 2023

terraform-plugin-testing version

1.4.0

Relevant provider source code

package provider

import (
	"testing"

	"github.com/hashicorp/terraform-plugin-go/tfprotov5"
	"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestMuxServer(t *testing.T) {
	resource.Test(t, resource.TestCase{
		ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){
			"brightbox": func() (tfprotov5.ProviderServer, error) {
				providerServerCreator, err := BrightboxTF5ProviderServerCreatorFactory("test")
				if err != nil {
					return nil, err
				}
				return providerServerCreator(), nil
			},
		},
		Steps: []resource.TestStep{
			{
				Config: `resource "brightbox_server_group" "default" {
						  name = "Used by the terraform"
						}`,
			},
		},
	})
}

package provider

import (
	"context"

	sdkprovider "github.com/brightbox/terraform-provider-brightbox/brightbox"
	"github.com/hashicorp/terraform-plugin-framework/providerserver"
	"github.com/hashicorp/terraform-plugin-go/tfprotov5"
	"github.com/hashicorp/terraform-plugin-mux/tf5muxserver"
)

// BrightboxTF5ProviderServerCreatorFactory returns a function that will create a
// Provider Server.
func BrightboxTF5ProviderServerCreatorFactory(name string) (func() tfprotov5.ProviderServer, error) {
	ctx := context.Background()
	providers := []func() tfprotov5.ProviderServer{
		sdkprovider.Provider().GRPCProvider,    //SDK Brightbox provider
		providerserver.NewProtocol5(New(name)), // This provider
	}

	muxServer, err := tf5muxserver.NewMuxServer(ctx, providers...)

	if err != nil {
		return nil, err
	}

	return muxServer.ProviderServer, nil
}

Expected Behavior

Provider test runs

Actual Behavior

$ go test
/tmp/go-build1374472121/b001/provider.test flag redefined: sweep
panic: /tmp/go-build1374472121/b001/provider.test flag redefined: sweep

goroutine 1 [running]:
flag.(*FlagSet).Var(0xc000124120, {0x1146318, 0xc0002af8b0}, {0xfbc5a0, 0x5}, {0xfe58de, 0x29})
/snap/go/current/src/flag/flag.go:982 +0x2f9
flag.(*FlagSet).StringVar(...)
/snap/go/current/src/flag/flag.go:847
flag.(*FlagSet).String(0x8?, {0xfbc5a0, 0x5}, {0x0, 0x0}, {0xfe58de, 0x29})
/snap/go/current/src/flag/flag.go:860 +0xac
flag.String(...)
/snap/go/current/src/flag/flag.go:867
github.com/hashicorp/terraform-plugin-testing/helper/resource.init()
/home/neil/Go/pkg/mod/github.com/hashicorp/[email protected]/helper/resource/testing.go:55 +0x45
exit status 2
FAIL github.com/brightbox/terraform-provider-brightbox/internal/provider 0.010s

Steps to Reproduce

go test

@NeilW NeilW added the bug Something isn't working label Jul 27, 2023
@bendbennett
Copy link
Contributor

Hi @NeilW 👋

I think the likely explanation for the panic you are seeing is because you are importing github.com/hashicorp/terraform-plugin-testing/helper/resource and in the sdkprovider (i.e., github.com/brightbox/terraform-provider-brightbox/brightbox) you are using github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource for example in resource_brightbox_server.go.

You should be able to migrate your acceptance testing dependencies in terraform-provider-brightbox from SDKv2 to the Plugin Testing module by following these steps.

@NeilW
Copy link
Author

NeilW commented Jul 27, 2023

Really not sure how I missed that. Thanks

@NeilW NeilW closed this as completed Jul 27, 2023
@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants