Hello! How should we handle mocking register compo...
# general
e
Hello! How should we handle mocking register component resources for testing purposes. I followed the unit testing guide for golang here. When I ran my test against this code snippet…
Copy code
func NewAKSComponent(ctx *pulumi.Context, name string, params Parameters, opts ...pulumi.ResourceOption) (*Component, error) {
	aksComponent := &Component{}

	err := ctx.RegisterComponentResource("r1-compute-infra:k8scp:AKSComponent", name, aksComponent, opts...)
I got this error
Copy code
--- FAIL: TestAKSComponent (0.00s)
    /workspaces/r1-compute-infra/pkg/aks/index_test.go:26: 
        	Error Trace:	index_test.go:26
        	            				run.go:103
        	            				run.go:84
        	            				index_test.go:24
        	Error:      	Received unexpected error:
        	            	resource name argument (for URN creation) cannot be empty
        	            	RegisterComponentResource failed
        	            	<http://github.com/relativityone/r1-compute-infra/pkg/aks.NewAKSComponent|github.com/relativityone/r1-compute-infra/pkg/aks.NewAKSComponent>
        	            		/workspaces/r1-compute-infra/pkg/aks/index.go:48
        	            	<http://github.com/relativityone/r1-compute-infra/pkg/aks.TestAKSComponent.func1|github.com/relativityone/r1-compute-infra/pkg/aks.TestAKSComponent.func1>
        	            		/workspaces/r1-compute-infra/pkg/aks/index_test.go:25
        	            	<http://github.com/pulumi/pulumi/sdk/v3/go/pulumi.RunWithContext|github.com/pulumi/pulumi/sdk/v3/go/pulumi.RunWithContext>
        	            		/home/vscode/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.1.0/go/pulumi/run.go:103
        	            	<http://github.com/pulumi/pulumi/sdk/v3/go/pulumi.RunErr|github.com/pulumi/pulumi/sdk/v3/go/pulumi.RunErr>
        	            		/home/vscode/go/pkg/mod/github.com/pulumi/pulumi/sdk/v3@v3.1.0/go/pulumi/run.go:84
        	            	<http://github.com/relativityone/r1-compute-infra/pkg/aks.TestAKSComponent|github.com/relativityone/r1-compute-infra/pkg/aks.TestAKSComponent>
        	            		/workspaces/r1-compute-infra/pkg/aks/index_test.go:24
        	            	testing.tRunner
        	            		/usr/local/go/src/testing/testing.go:1194
        	            	runtime.goexit
        	            		/usr/local/go/src/runtime/asm_amd64.s:1371
        	Test:       	TestAKSComponent
Is there a process in place for testing resource components or is the way I’ve setup my code not the intended strategy? Currently, I’m calling
NewAKSComponent
to the AKS cluster and its azure resource group. Thanks!
Having digested this further, my understanding is Pulumi mocks are resource level abstractions. Component Resources a level above resources. I’m refactoring my code to break resource creating into separate functions.
pulumi.Parent(aksComponent)
will be passed in as a variadic argument. Yay TDD!