Skip to content

Commit

Permalink
Test generating structs containing generics
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSpiritXIII committed Nov 29, 2023
1 parent bfb8b73 commit dc15ff5
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 4 deletions.
34 changes: 34 additions & 0 deletions examples/deepcopy-gen/output_tests/generics/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// +k8s:deepcopy-gen=package

// This is a test package.
package generics

import (
"k8s.io/gengo/examples/deepcopy-gen/output_tests/structs"
)

type TunusedGeneric[T any] struct {
Inner1 structs.Inner
Inner2 structs.Inner
}

type TunusedGenericMulti[T any, U any, V any] struct {
Inner1 structs.Inner
Inner2 structs.Inner
}
58 changes: 58 additions & 0 deletions examples/deepcopy-gen/output_tests/generics/zz_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion examples/deepcopy-gen/output_tests/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"testing"

"github.com/davecgh/go-spew/spew"
"github.com/google/gofuzz"
fuzz "github.com/google/gofuzz"

"k8s.io/gengo/examples/deepcopy-gen/output_tests/aliases"
"k8s.io/gengo/examples/deepcopy-gen/output_tests/builtins"
"k8s.io/gengo/examples/deepcopy-gen/output_tests/generics"
"k8s.io/gengo/examples/deepcopy-gen/output_tests/interfaces"
"k8s.io/gengo/examples/deepcopy-gen/output_tests/maps"
"k8s.io/gengo/examples/deepcopy-gen/output_tests/pointer"
Expand All @@ -26,6 +27,9 @@ func TestWithValueFuzzer(t *testing.T) {
pointer.Ttest{},
slices.Ttest{},
structs.Ttest{},

generics.TunusedGeneric[int]{},
generics.TunusedGenericMulti[int, bool, byte]{},
}

fuzzer := fuzz.New()
Expand Down
12 changes: 9 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
module k8s.io/gengo

go 1.13
go 1.18

require (
github.com/davecgh/go-spew v1.1.1
github.com/google/go-cmp v0.4.0
github.com/google/gofuzz v1.1.0
github.com/kr/pretty v0.2.0 // indirect
github.com/spf13/pflag v1.0.5
golang.org/x/tools v0.0.0-20200505023115-26f46d2f7ef8
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
k8s.io/klog/v2 v2.2.0
sigs.k8s.io/yaml v1.2.0
)

require (
github.com/go-logr/logr v0.2.0 // indirect
github.com/kr/pretty v0.2.0 // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
)

replace (
golang.org/x/sys => golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // pinned to release-branch.go1.13
golang.org/x/tools => golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7 // pinned to release-branch.go1.13
Expand Down

0 comments on commit dc15ff5

Please sign in to comment.