diff --git a/cmd/libs/go2idl/client-gen/generators/fake/fake_client_generator.go b/cmd/libs/go2idl/client-gen/generators/fake/fake_client_generator.go index bf7cc5c4bf8..acea427078c 100644 --- a/cmd/libs/go2idl/client-gen/generators/fake/fake_client_generator.go +++ b/cmd/libs/go2idl/client-gen/generators/fake/fake_client_generator.go @@ -62,7 +62,7 @@ func PackageForGroup(gv unversioned.GroupVersion, typeList []*types.Type, packag generators = append(generators, &genFakeForGroup{ DefaultGen: generator.DefaultGen{ - OptionalName: "fake_" + gv.Group + "_client", + OptionalName: "fake_" + normalization.BeforeFirstDot(gv.Group) + "_client", }, outputPackage: outputPackagePath, realClientPath: realClientPath, diff --git a/cmd/libs/go2idl/client-gen/generators/fake/generator_fake_for_clientset.go b/cmd/libs/go2idl/client-gen/generators/fake/generator_fake_for_clientset.go index ced1f527d3d..c6f25e4017a 100644 --- a/cmd/libs/go2idl/client-gen/generators/fake/generator_fake_for_clientset.go +++ b/cmd/libs/go2idl/client-gen/generators/fake/generator_fake_for_clientset.go @@ -60,10 +60,11 @@ func (g *genClientset) Imports(c *generator.Context) (imports []string) { for _, gv := range g.groupVersions { group := normalization.Group(gv.Group) version := normalization.Version(gv.Version) + undotted_group := normalization.BeforeFirstDot(group) typedClientPath := filepath.Join(g.typedClientPath, group, version) - imports = append(imports, fmt.Sprintf("%s%s \"%s\"", version, group, typedClientPath)) + imports = append(imports, fmt.Sprintf("%s%s \"%s\"", version, undotted_group, typedClientPath)) fakeTypedClientPath := filepath.Join(typedClientPath, "fake") - imports = append(imports, fmt.Sprintf("fake%s%s \"%s\"", version, group, fakeTypedClientPath)) + imports = append(imports, fmt.Sprintf("fake%s%s \"%s\"", version, undotted_group, fakeTypedClientPath)) } // the package that has the clientset Interface imports = append(imports, fmt.Sprintf("clientset \"%s\"", g.clientsetPath)) @@ -96,7 +97,7 @@ func (g *genClientset) GenerateType(c *generator.Context, t *types.Type, w io.Wr } allGroups := []arg{} for _, gv := range g.groupVersions { - group := normalization.Group(gv.Group) + group := normalization.BeforeFirstDot(normalization.Group(gv.Group)) version := normalization.Version(gv.Version) allGroups = append(allGroups, arg{namer.IC(group), version + group}) } diff --git a/cmd/libs/go2idl/client-gen/main.go b/cmd/libs/go2idl/client-gen/main.go index d51575a97c4..fc6244ad0d2 100644 --- a/cmd/libs/go2idl/client-gen/main.go +++ b/cmd/libs/go2idl/client-gen/main.go @@ -102,7 +102,7 @@ func main() { ClientsetName: "test_internalclientset", ClientsetOutputPath: "k8s.io/kubernetes/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/", ClientsetOnly: false, - FakeClient: false, + FakeClient: true, CmdArgs: cmdArgs, } } else { diff --git a/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/fake/clientset_generated.go b/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/fake/clientset_generated.go new file mode 100644 index 00000000000..ae502b95b76 --- /dev/null +++ b/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/fake/clientset_generated.go @@ -0,0 +1,65 @@ +/* +Copyright 2016 The Kubernetes Authors All rights reserved. + +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. +*/ + +package fake + +import ( + clientset "k8s.io/kubernetes/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset" + unversionedtestgroup "k8s.io/kubernetes/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/typed/testgroup.k8s.io/unversioned" + fakeunversionedtestgroup "k8s.io/kubernetes/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/typed/testgroup.k8s.io/unversioned/fake" + "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/apimachinery/registered" + "k8s.io/kubernetes/pkg/client/testing/core" + "k8s.io/kubernetes/pkg/client/typed/discovery" + fakediscovery "k8s.io/kubernetes/pkg/client/typed/discovery/fake" + "k8s.io/kubernetes/pkg/runtime" + "k8s.io/kubernetes/pkg/watch" +) + +// Clientset returns a clientset that will respond with the provided objects +func NewSimpleClientset(objects ...runtime.Object) *Clientset { + o := core.NewObjects(api.Scheme, api.Codecs.UniversalDecoder()) + for _, obj := range objects { + if err := o.Add(obj); err != nil { + panic(err) + } + } + + fakePtr := core.Fake{} + fakePtr.AddReactor("*", "*", core.ObjectReaction(o, registered.RESTMapper())) + + fakePtr.AddWatchReactor("*", core.DefaultWatchReactor(watch.NewFake(), nil)) + + return &Clientset{fakePtr} +} + +// Clientset implements clientset.Interface. Meant to be embedded into a +// struct to get a default implementation. This makes faking out just the method +// you want to test easier. +type Clientset struct { + core.Fake +} + +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + return &fakediscovery.FakeDiscovery{&c.Fake} +} + +var _ clientset.Interface = &Clientset{} + +// Testgroup retrieves the TestgroupClient +func (c *Clientset) Testgroup() unversionedtestgroup.TestgroupInterface { + return &fakeunversionedtestgroup.FakeTestgroup{&c.Fake} +} diff --git a/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/fake/doc.go b/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/fake/doc.go new file mode 100644 index 00000000000..8f18be02a69 --- /dev/null +++ b/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright 2016 The Kubernetes Authors All rights reserved. + +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. +*/ + +// This package is generated by client-gen with arguments: --test=true + +// This package has the automatically generated fake clientset. +package fake diff --git a/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/typed/testgroup.k8s.io/unversioned/fake/doc.go b/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/typed/testgroup.k8s.io/unversioned/fake/doc.go new file mode 100644 index 00000000000..30080cb0a64 --- /dev/null +++ b/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/typed/testgroup.k8s.io/unversioned/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright 2016 The Kubernetes Authors All rights reserved. + +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. +*/ + +// This package is generated by client-gen with arguments: --test=true + +// Package fake has the automatically generated clients. +package fake diff --git a/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/typed/testgroup.k8s.io/unversioned/fake/fake_testgroup_client.go b/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/typed/testgroup.k8s.io/unversioned/fake/fake_testgroup_client.go new file mode 100644 index 00000000000..eba165e0bea --- /dev/null +++ b/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/typed/testgroup.k8s.io/unversioned/fake/fake_testgroup_client.go @@ -0,0 +1,30 @@ +/* +Copyright 2016 The Kubernetes Authors All rights reserved. + +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. +*/ + +package fake + +import ( + unversioned "k8s.io/kubernetes/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/typed/testgroup.k8s.io/unversioned" + core "k8s.io/kubernetes/pkg/client/testing/core" +) + +type FakeTestgroup struct { + *core.Fake +} + +func (c *FakeTestgroup) TestTypes(namespace string) unversioned.TestTypeInterface { + return &FakeTestTypes{c, namespace} +} diff --git a/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/typed/testgroup.k8s.io/unversioned/fake/fake_testtype.go b/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/typed/testgroup.k8s.io/unversioned/fake/fake_testtype.go new file mode 100644 index 00000000000..9fdb8b5d7b3 --- /dev/null +++ b/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/typed/testgroup.k8s.io/unversioned/fake/fake_testtype.go @@ -0,0 +1,113 @@ +/* +Copyright 2016 The Kubernetes Authors All rights reserved. + +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. +*/ + +package fake + +import ( + testgroup_k8s_io "k8s.io/kubernetes/cmd/libs/go2idl/client-gen/testdata/apis/testgroup.k8s.io" + api "k8s.io/kubernetes/pkg/api" + core "k8s.io/kubernetes/pkg/client/testing/core" + labels "k8s.io/kubernetes/pkg/labels" + watch "k8s.io/kubernetes/pkg/watch" +) + +// FakeTestTypes implements TestTypeInterface +type FakeTestTypes struct { + Fake *FakeTestgroup + ns string +} + +func (c *FakeTestTypes) Create(testType *testgroup_k8s_io.TestType) (result *testgroup_k8s_io.TestType, err error) { + obj, err := c.Fake. + Invokes(core.NewCreateAction("testtypes", c.ns, testType), &testgroup_k8s_io.TestType{}) + + if obj == nil { + return nil, err + } + return obj.(*testgroup_k8s_io.TestType), err +} + +func (c *FakeTestTypes) Update(testType *testgroup_k8s_io.TestType) (result *testgroup_k8s_io.TestType, err error) { + obj, err := c.Fake. + Invokes(core.NewUpdateAction("testtypes", c.ns, testType), &testgroup_k8s_io.TestType{}) + + if obj == nil { + return nil, err + } + return obj.(*testgroup_k8s_io.TestType), err +} + +func (c *FakeTestTypes) UpdateStatus(testType *testgroup_k8s_io.TestType) (*testgroup_k8s_io.TestType, error) { + obj, err := c.Fake. + Invokes(core.NewUpdateSubresourceAction("testtypes", "status", c.ns, testType), &testgroup_k8s_io.TestType{}) + + if obj == nil { + return nil, err + } + return obj.(*testgroup_k8s_io.TestType), err +} + +func (c *FakeTestTypes) Delete(name string, options *api.DeleteOptions) error { + _, err := c.Fake. + Invokes(core.NewDeleteAction("testtypes", c.ns, name), &testgroup_k8s_io.TestType{}) + + return err +} + +func (c *FakeTestTypes) DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error { + action := core.NewDeleteCollectionAction("testtypes", c.ns, listOptions) + + _, err := c.Fake.Invokes(action, &testgroup_k8s_io.TestTypeList{}) + return err +} + +func (c *FakeTestTypes) Get(name string) (result *testgroup_k8s_io.TestType, err error) { + obj, err := c.Fake. + Invokes(core.NewGetAction("testtypes", c.ns, name), &testgroup_k8s_io.TestType{}) + + if obj == nil { + return nil, err + } + return obj.(*testgroup_k8s_io.TestType), err +} + +func (c *FakeTestTypes) List(opts api.ListOptions) (result *testgroup_k8s_io.TestTypeList, err error) { + obj, err := c.Fake. + Invokes(core.NewListAction("testtypes", c.ns, opts), &testgroup_k8s_io.TestTypeList{}) + + if obj == nil { + return nil, err + } + + label := opts.LabelSelector + if label == nil { + label = labels.Everything() + } + list := &testgroup_k8s_io.TestTypeList{} + for _, item := range obj.(*testgroup_k8s_io.TestTypeList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested testTypes. +func (c *FakeTestTypes) Watch(opts api.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(core.NewWatchAction("testtypes", c.ns, opts)) + +} diff --git a/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/typed/testgroup.k8s.io/unversioned/fake/fake_testtype_expansion.go b/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/typed/testgroup.k8s.io/unversioned/fake/fake_testtype_expansion.go new file mode 100644 index 00000000000..691dd510012 --- /dev/null +++ b/cmd/libs/go2idl/client-gen/testoutput/clientset_generated/test_internalclientset/typed/testgroup.k8s.io/unversioned/fake/fake_testtype_expansion.go @@ -0,0 +1,21 @@ +/* +Copyright 2016 The Kubernetes Authors All rights reserved. + +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. +*/ + +package fake + +func (c *FakeTestTypes) Hello() string { + return "hello!" +}