-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chao Xu
committed
May 15, 2017
1 parent
af11bb5
commit 29bd77c
Showing
7 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
TOOL=defaulter-gen | ||
|
||
test: | ||
@if ! git diff --quiet HEAD; then \ | ||
echo "FAIL: git client is not clean"; \ | ||
false; \ | ||
fi | ||
@go build -o /tmp/$(TOOL) | ||
/tmp/$(TOOL) --logtostderr --v=6 -i ./output_tests/wholepkg -O zz_generated | ||
@if ! diff -q ./output_tests/wholepkg/zz_generated.expected ./output_tests/wholepkg/zz_generated.go; then \ | ||
echo "FAIL: output files changed"; \ | ||
diff ./output_tests/wholepkg/zz_generated.expected ./output_tests/wholepkg/zz_generated.go; \ | ||
false; \ | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
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. | ||
*/ | ||
|
||
package wholepkg | ||
|
||
type ManualDefault struct{} | ||
|
||
func SetDefaults_ManualDefault(obj *ManualDefault) { | ||
} | ||
|
||
type Stuct_With_Field_Has_Manual_Defaulter struct { | ||
TypeMeta struct{} | ||
ManualDefault ManualDefault | ||
OtherField string | ||
} | ||
|
||
type Stuct_With_Field_With_Field_Has_Manual_Defaulter struct { | ||
TypeMeta struct{} | ||
Stuct_With_Field_Has_Manual_Defaulter | ||
OtherField string | ||
} | ||
|
||
// No defaulter will be generated | ||
type Stuct_No_Field_Has_Manual_Defaulter struct { | ||
TypeMeta struct{} | ||
OtherField string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
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. | ||
*/ | ||
|
||
package wholepkg | ||
|
||
// Another type in another file. | ||
type Struct_B struct{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
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:defaulter-gen=TypeMeta | ||
|
||
// This is a test package. | ||
package wholepkg |
22 changes: 22 additions & 0 deletions
22
examples/defaulter-gen/output_tests/wholepkg/vendor/k8s.io/apimachinery/pkg/runtime/mock.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
examples/defaulter-gen/output_tests/wholepkg/zz_generated.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// +build !ignore_autogenerated | ||
|
||
/* | ||
Copyright 2017 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. | ||
*/ | ||
|
||
// This file was autogenerated by defaulter-gen. Do not edit it manually! | ||
|
||
package wholepkg | ||
|
||
import ( | ||
runtime "k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
// RegisterDefaults adds defaulters functions to the given scheme. | ||
// Public to allow building arbitrary schemes. | ||
// All generated defaulters are covering - they call all nested defaulters. | ||
func RegisterDefaults(scheme *runtime.Scheme) error { | ||
scheme.AddTypeDefaultingFunc(&Stuct_With_Field_Has_Manual_Defaulter{}, func(obj interface{}) { | ||
SetObjectDefaults_Stuct_With_Field_Has_Manual_Defaulter(obj.(*Stuct_With_Field_Has_Manual_Defaulter)) | ||
}) | ||
scheme.AddTypeDefaultingFunc(&Stuct_With_Field_With_Field_Has_Manual_Defaulter{}, func(obj interface{}) { | ||
SetObjectDefaults_Stuct_With_Field_With_Field_Has_Manual_Defaulter(obj.(*Stuct_With_Field_With_Field_Has_Manual_Defaulter)) | ||
}) | ||
return nil | ||
} | ||
|
||
func SetObjectDefaults_Stuct_With_Field_Has_Manual_Defaulter(in *Stuct_With_Field_Has_Manual_Defaulter) { | ||
SetDefaults_ManualDefault(&in.ManualDefault) | ||
} | ||
|
||
func SetObjectDefaults_Stuct_With_Field_With_Field_Has_Manual_Defaulter(in *Stuct_With_Field_With_Field_Has_Manual_Defaulter) { | ||
SetObjectDefaults_Stuct_With_Field_Has_Manual_Defaulter(&in.Stuct_With_Field_Has_Manual_Defaulter) | ||
} |
46 changes: 46 additions & 0 deletions
46
examples/defaulter-gen/output_tests/wholepkg/zz_generated.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// +build !ignore_autogenerated | ||
|
||
/* | ||
Copyright 2017 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. | ||
*/ | ||
|
||
// This file was autogenerated by defaulter-gen. Do not edit it manually! | ||
|
||
package wholepkg | ||
|
||
import ( | ||
runtime "k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
// RegisterDefaults adds defaulters functions to the given scheme. | ||
// Public to allow building arbitrary schemes. | ||
// All generated defaulters are covering - they call all nested defaulters. | ||
func RegisterDefaults(scheme *runtime.Scheme) error { | ||
scheme.AddTypeDefaultingFunc(&Stuct_With_Field_Has_Manual_Defaulter{}, func(obj interface{}) { | ||
SetObjectDefaults_Stuct_With_Field_Has_Manual_Defaulter(obj.(*Stuct_With_Field_Has_Manual_Defaulter)) | ||
}) | ||
scheme.AddTypeDefaultingFunc(&Stuct_With_Field_With_Field_Has_Manual_Defaulter{}, func(obj interface{}) { | ||
SetObjectDefaults_Stuct_With_Field_With_Field_Has_Manual_Defaulter(obj.(*Stuct_With_Field_With_Field_Has_Manual_Defaulter)) | ||
}) | ||
return nil | ||
} | ||
|
||
func SetObjectDefaults_Stuct_With_Field_Has_Manual_Defaulter(in *Stuct_With_Field_Has_Manual_Defaulter) { | ||
SetDefaults_ManualDefault(&in.ManualDefault) | ||
} | ||
|
||
func SetObjectDefaults_Stuct_With_Field_With_Field_Has_Manual_Defaulter(in *Stuct_With_Field_With_Field_Has_Manual_Defaulter) { | ||
SetObjectDefaults_Stuct_With_Field_Has_Manual_Defaulter(&in.Stuct_With_Field_Has_Manual_Defaulter) | ||
} |