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

bug: Autogenerated files do not handle custom types properly #135

Open
warango4 opened this issue Apr 10, 2024 · 1 comment
Open

bug: Autogenerated files do not handle custom types properly #135

warango4 opened this issue Apr 10, 2024 · 1 comment

Comments

@warango4
Copy link

warango4 commented Apr 10, 2024

As part of a new plugin testing, we're trying to add dies package to better manage object/resources in unit testing.
However, when running the dies generator command, the autogenerated file comes with a weird import:

apicappsv1 "map[whatevergit.com/pkg/app-resource/api/capps/v1" // this is the first import which contains extra characters
cappsv1 "whatevergit.com/pkg/app-resource/api/capps/v1" // this is the second import, poiting to the same repo but with a different name

and also, the funcs that ask for a map[<customType>]anything, fail by creating the following func signature:

// should be v map[apicappsv1.ContentKey]string
func (d *AppSpecDie) Content(v apicappsv1.ContentKey]string) *AppSpecDie {...}

Since ContentKey is type ContentKey string, I tried adding it to my app_types.go file like this:

// +die:object=true,spec=AppSpec,status=AppStatus
type _ = app.App

// +die
type _ = app.AppSpec

// +die
type _ = app.AppStatus

// +die
type _ = app.ResourcesKey

// +die
type _ = app.ContentKey

When running:

go run -modfile hack/go.mod -mod=mod dies.dev/diegen die:headerFile="hack/boilerplate.go.txt" paths="./..."

I get the following error:

...
Generating die for "ResourcesKey"
Generating die for "ContentKey"
519:62: missing ',' in parameter list # this line is where the map is not properly created for ContentKey
563:66: missing ',' in parameter list # this line is where the map is not properly created for ResourcesKey
panic: true

goroutine 1 [running]:
main.main()
        /Users/wendyarango/go/pkg/mod/reconciler.io/dies/[email protected]/main.go:45 +0xfc

Is it possible I'm doing something wrong? Thanks for your help

@scothis
Copy link
Collaborator

scothis commented Apr 10, 2024

Hi @warango4

Yea, maps with non-primitive keys are not handled well. You can work around this by ignoring the specific field that is causing trouble and manually defining the methods you care about.

For example:

// +die:ignore={Extra}
type _ = authenticationv1.UserInfo
// Any additional information provided by the authenticator.
func (d *UserInfoDie) Extra(v map[string]authenticationv1.ExtraValue) *UserInfoDie {
return d.DieStamp(func(r *authenticationv1.UserInfo) {
r.Extra = v
})
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants