diff --git a/pkg/api/persistentvolumeclaim/BUILD b/pkg/api/persistentvolumeclaim/BUILD index 3a72b78c8f0..fba0dfd6598 100644 --- a/pkg/api/persistentvolumeclaim/BUILD +++ b/pkg/api/persistentvolumeclaim/BUILD @@ -32,7 +32,10 @@ filegroup( go_test( name = "go_default_test", - srcs = ["util_test.go"], + srcs = [ + "main_test.go", + "util_test.go", + ], embed = [":go_default_library"], deps = [ "//pkg/apis/core:go_default_library", diff --git a/pkg/api/persistentvolumeclaim/main_test.go b/pkg/api/persistentvolumeclaim/main_test.go new file mode 100644 index 00000000000..3ce0a93c8c1 --- /dev/null +++ b/pkg/api/persistentvolumeclaim/main_test.go @@ -0,0 +1,29 @@ +/* +Copyright 2018 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 persistentvolumeclaim + +import ( + "testing" + + utilfeature "k8s.io/apiserver/pkg/util/feature" + utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing" + _ "k8s.io/kubernetes/pkg/features" +) + +func TestMain(m *testing.M) { + utilfeaturetesting.VerifyFeatureGatesUnchanged(utilfeature.DefaultFeatureGate, m.Run) +} diff --git a/pkg/api/pod/BUILD b/pkg/api/pod/BUILD index 2da65ee0c57..5721392c09a 100644 --- a/pkg/api/pod/BUILD +++ b/pkg/api/pod/BUILD @@ -33,7 +33,10 @@ filegroup( go_test( name = "go_default_test", - srcs = ["util_test.go"], + srcs = [ + "main_test.go", + "util_test.go", + ], embed = [":go_default_library"], deps = [ "//pkg/apis/core:go_default_library", diff --git a/pkg/api/pod/main_test.go b/pkg/api/pod/main_test.go new file mode 100644 index 00000000000..4fb45213978 --- /dev/null +++ b/pkg/api/pod/main_test.go @@ -0,0 +1,29 @@ +/* +Copyright 2018 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 pod + +import ( + "testing" + + utilfeature "k8s.io/apiserver/pkg/util/feature" + utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing" + _ "k8s.io/kubernetes/pkg/features" +) + +func TestMain(m *testing.M) { + utilfeaturetesting.VerifyFeatureGatesUnchanged(utilfeature.DefaultFeatureGate, m.Run) +} diff --git a/pkg/api/podsecuritypolicy/BUILD b/pkg/api/podsecuritypolicy/BUILD index 4c1f9db836f..4d566715fb7 100644 --- a/pkg/api/podsecuritypolicy/BUILD +++ b/pkg/api/podsecuritypolicy/BUILD @@ -32,12 +32,16 @@ filegroup( go_test( name = "go_default_test", - srcs = ["util_test.go"], + srcs = [ + "main_test.go", + "util_test.go", + ], embed = [":go_default_library"], deps = [ "//pkg/apis/core:go_default_library", "//pkg/apis/policy:go_default_library", "//pkg/features:go_default_library", "//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library", + "//staging/src/k8s.io/apiserver/pkg/util/feature/testing:go_default_library", ], ) diff --git a/pkg/api/podsecuritypolicy/main_test.go b/pkg/api/podsecuritypolicy/main_test.go new file mode 100644 index 00000000000..f379a10cfbe --- /dev/null +++ b/pkg/api/podsecuritypolicy/main_test.go @@ -0,0 +1,29 @@ +/* +Copyright 2018 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 podsecuritypolicy + +import ( + "testing" + + utilfeature "k8s.io/apiserver/pkg/util/feature" + utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing" + _ "k8s.io/kubernetes/pkg/features" +) + +func TestMain(m *testing.M) { + utilfeaturetesting.VerifyFeatureGatesUnchanged(utilfeature.DefaultFeatureGate, m.Run) +} diff --git a/pkg/apis/batch/validation/BUILD b/pkg/apis/batch/validation/BUILD index d371966a354..4a29be29ae2 100644 --- a/pkg/apis/batch/validation/BUILD +++ b/pkg/apis/batch/validation/BUILD @@ -27,7 +27,10 @@ go_library( go_test( name = "go_default_test", - srcs = ["validation_test.go"], + srcs = [ + "main_test.go", + "validation_test.go", + ], embed = [":go_default_library"], deps = [ "//pkg/apis/batch:go_default_library", @@ -36,6 +39,7 @@ go_test( "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/types:go_default_library", "//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library", + "//staging/src/k8s.io/apiserver/pkg/util/feature/testing:go_default_library", ], ) diff --git a/pkg/apis/batch/validation/main_test.go b/pkg/apis/batch/validation/main_test.go new file mode 100644 index 00000000000..ad488a1caaa --- /dev/null +++ b/pkg/apis/batch/validation/main_test.go @@ -0,0 +1,29 @@ +/* +Copyright 2018 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 validation + +import ( + "testing" + + utilfeature "k8s.io/apiserver/pkg/util/feature" + utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing" + _ "k8s.io/kubernetes/pkg/features" +) + +func TestMain(m *testing.M) { + utilfeaturetesting.VerifyFeatureGatesUnchanged(utilfeature.DefaultFeatureGate, m.Run) +} diff --git a/pkg/apis/core/v1/BUILD b/pkg/apis/core/v1/BUILD index 16e3e13d8f0..b7e881dd95c 100644 --- a/pkg/apis/core/v1/BUILD +++ b/pkg/apis/core/v1/BUILD @@ -36,6 +36,7 @@ go_test( srcs = [ "conversion_test.go", "defaults_test.go", + "main_test.go", ], embed = [":go_default_library"], deps = [ @@ -44,6 +45,7 @@ go_test( "//pkg/apis/apps:go_default_library", "//pkg/apis/core:go_default_library", "//pkg/apis/core/fuzzer:go_default_library", + "//pkg/features:go_default_library", "//staging/src/k8s.io/api/apps/v1:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/api/apitesting/fuzzer:go_default_library", @@ -55,6 +57,7 @@ go_test( "//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/intstr:go_default_library", "//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library", + "//staging/src/k8s.io/apiserver/pkg/util/feature/testing:go_default_library", "//vendor/k8s.io/utils/pointer:go_default_library", ], ) diff --git a/pkg/apis/core/v1/main_test.go b/pkg/apis/core/v1/main_test.go new file mode 100644 index 00000000000..e46b01929f7 --- /dev/null +++ b/pkg/apis/core/v1/main_test.go @@ -0,0 +1,29 @@ +/* +Copyright 2018 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 v1 + +import ( + "testing" + + utilfeature "k8s.io/apiserver/pkg/util/feature" + utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing" + _ "k8s.io/kubernetes/pkg/features" +) + +func TestMain(m *testing.M) { + utilfeaturetesting.VerifyFeatureGatesUnchanged(utilfeature.DefaultFeatureGate, m.Run) +} diff --git a/pkg/apis/core/validation/BUILD b/pkg/apis/core/validation/BUILD index ed546217cf6..a815e5b0ac7 100644 --- a/pkg/apis/core/validation/BUILD +++ b/pkg/apis/core/validation/BUILD @@ -47,6 +47,7 @@ go_test( name = "go_default_test", srcs = [ "events_test.go", + "main_test.go", "validation_test.go", ], embed = [":go_default_library"], diff --git a/pkg/apis/core/validation/main_test.go b/pkg/apis/core/validation/main_test.go new file mode 100644 index 00000000000..ad488a1caaa --- /dev/null +++ b/pkg/apis/core/validation/main_test.go @@ -0,0 +1,29 @@ +/* +Copyright 2018 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 validation + +import ( + "testing" + + utilfeature "k8s.io/apiserver/pkg/util/feature" + utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing" + _ "k8s.io/kubernetes/pkg/features" +) + +func TestMain(m *testing.M) { + utilfeaturetesting.VerifyFeatureGatesUnchanged(utilfeature.DefaultFeatureGate, m.Run) +} diff --git a/pkg/apis/storage/util/BUILD b/pkg/apis/storage/util/BUILD index 1b37c7f631d..0cddfad64b4 100644 --- a/pkg/apis/storage/util/BUILD +++ b/pkg/apis/storage/util/BUILD @@ -36,7 +36,10 @@ filegroup( go_test( name = "go_default_test", - srcs = ["util_test.go"], + srcs = [ + "main_test.go", + "util_test.go", + ], embed = [":go_default_library"], deps = [ "//pkg/apis/core:go_default_library", diff --git a/pkg/apis/storage/util/main_test.go b/pkg/apis/storage/util/main_test.go new file mode 100644 index 00000000000..6af02d0a11d --- /dev/null +++ b/pkg/apis/storage/util/main_test.go @@ -0,0 +1,29 @@ +/* +Copyright 2018 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 util + +import ( + "testing" + + utilfeature "k8s.io/apiserver/pkg/util/feature" + utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing" + _ "k8s.io/kubernetes/pkg/features" +) + +func TestMain(m *testing.M) { + utilfeaturetesting.VerifyFeatureGatesUnchanged(utilfeature.DefaultFeatureGate, m.Run) +} diff --git a/pkg/apis/storage/v1/BUILD b/pkg/apis/storage/v1/BUILD index 05bd5565a79..11449ae5f12 100644 --- a/pkg/apis/storage/v1/BUILD +++ b/pkg/apis/storage/v1/BUILD @@ -47,7 +47,10 @@ filegroup( go_test( name = "go_default_test", - srcs = ["defaults_test.go"], + srcs = [ + "defaults_test.go", + "main_test.go", + ], embed = [":go_default_library"], deps = [ "//pkg/api/legacyscheme:go_default_library", diff --git a/pkg/apis/storage/v1/main_test.go b/pkg/apis/storage/v1/main_test.go new file mode 100644 index 00000000000..e46b01929f7 --- /dev/null +++ b/pkg/apis/storage/v1/main_test.go @@ -0,0 +1,29 @@ +/* +Copyright 2018 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 v1 + +import ( + "testing" + + utilfeature "k8s.io/apiserver/pkg/util/feature" + utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing" + _ "k8s.io/kubernetes/pkg/features" +) + +func TestMain(m *testing.M) { + utilfeaturetesting.VerifyFeatureGatesUnchanged(utilfeature.DefaultFeatureGate, m.Run) +} diff --git a/pkg/apis/storage/v1beta1/BUILD b/pkg/apis/storage/v1beta1/BUILD index 7be33870151..4695a2ddb21 100644 --- a/pkg/apis/storage/v1beta1/BUILD +++ b/pkg/apis/storage/v1beta1/BUILD @@ -47,7 +47,10 @@ filegroup( go_test( name = "go_default_test", - srcs = ["defaults_test.go"], + srcs = [ + "defaults_test.go", + "main_test.go", + ], embed = [":go_default_library"], deps = [ "//pkg/api/legacyscheme:go_default_library", diff --git a/pkg/apis/storage/v1beta1/main_test.go b/pkg/apis/storage/v1beta1/main_test.go new file mode 100644 index 00000000000..4613d1156c4 --- /dev/null +++ b/pkg/apis/storage/v1beta1/main_test.go @@ -0,0 +1,29 @@ +/* +Copyright 2018 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 v1beta1 + +import ( + "testing" + + utilfeature "k8s.io/apiserver/pkg/util/feature" + utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing" + _ "k8s.io/kubernetes/pkg/features" +) + +func TestMain(m *testing.M) { + utilfeaturetesting.VerifyFeatureGatesUnchanged(utilfeature.DefaultFeatureGate, m.Run) +} diff --git a/pkg/apis/storage/validation/BUILD b/pkg/apis/storage/validation/BUILD index a91f11d93e1..fec90d3adcb 100644 --- a/pkg/apis/storage/validation/BUILD +++ b/pkg/apis/storage/validation/BUILD @@ -26,7 +26,10 @@ go_library( go_test( name = "go_default_test", - srcs = ["validation_test.go"], + srcs = [ + "main_test.go", + "validation_test.go", + ], embed = [":go_default_library"], deps = [ "//pkg/apis/core:go_default_library", diff --git a/pkg/apis/storage/validation/main_test.go b/pkg/apis/storage/validation/main_test.go new file mode 100644 index 00000000000..ad488a1caaa --- /dev/null +++ b/pkg/apis/storage/validation/main_test.go @@ -0,0 +1,29 @@ +/* +Copyright 2018 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 validation + +import ( + "testing" + + utilfeature "k8s.io/apiserver/pkg/util/feature" + utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing" + _ "k8s.io/kubernetes/pkg/features" +) + +func TestMain(m *testing.M) { + utilfeaturetesting.VerifyFeatureGatesUnchanged(utilfeature.DefaultFeatureGate, m.Run) +} diff --git a/pkg/controller/volume/persistentvolume/BUILD b/pkg/controller/volume/persistentvolume/BUILD index aac87f389d9..ae16c23f113 100644 --- a/pkg/controller/volume/persistentvolume/BUILD +++ b/pkg/controller/volume/persistentvolume/BUILD @@ -70,6 +70,7 @@ go_test( "delete_test.go", "framework_test.go", "index_test.go", + "main_test.go", "provision_test.go", "pv_controller_test.go", "recycle_test.go", diff --git a/pkg/controller/volume/persistentvolume/main_test.go b/pkg/controller/volume/persistentvolume/main_test.go new file mode 100644 index 00000000000..490540aa60b --- /dev/null +++ b/pkg/controller/volume/persistentvolume/main_test.go @@ -0,0 +1,29 @@ +/* +Copyright 2018 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 persistentvolume + +import ( + "testing" + + utilfeature "k8s.io/apiserver/pkg/util/feature" + utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing" + _ "k8s.io/kubernetes/pkg/features" +) + +func TestMain(m *testing.M) { + utilfeaturetesting.VerifyFeatureGatesUnchanged(utilfeature.DefaultFeatureGate, m.Run) +} diff --git a/pkg/kubelet/volumemanager/populator/BUILD b/pkg/kubelet/volumemanager/populator/BUILD index f038b0d32e6..a41a69e0cf5 100644 --- a/pkg/kubelet/volumemanager/populator/BUILD +++ b/pkg/kubelet/volumemanager/populator/BUILD @@ -47,7 +47,10 @@ filegroup( go_test( name = "go_default_test", - srcs = ["desired_state_of_world_populator_test.go"], + srcs = [ + "desired_state_of_world_populator_test.go", + "main_test.go", + ], embed = [":go_default_library"], deps = [ "//pkg/features:go_default_library", diff --git a/pkg/kubelet/volumemanager/populator/main_test.go b/pkg/kubelet/volumemanager/populator/main_test.go new file mode 100644 index 00000000000..de49504ed70 --- /dev/null +++ b/pkg/kubelet/volumemanager/populator/main_test.go @@ -0,0 +1,29 @@ +/* +Copyright 2018 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 populator + +import ( + "testing" + + utilfeature "k8s.io/apiserver/pkg/util/feature" + utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing" + _ "k8s.io/kubernetes/pkg/features" +) + +func TestMain(m *testing.M) { + utilfeaturetesting.VerifyFeatureGatesUnchanged(utilfeature.DefaultFeatureGate, m.Run) +} diff --git a/pkg/kubelet/volumemanager/reconciler/BUILD b/pkg/kubelet/volumemanager/reconciler/BUILD index e230dab4551..1ba3ced2f32 100644 --- a/pkg/kubelet/volumemanager/reconciler/BUILD +++ b/pkg/kubelet/volumemanager/reconciler/BUILD @@ -35,7 +35,10 @@ go_library( go_test( name = "go_default_test", - srcs = ["reconciler_test.go"], + srcs = [ + "main_test.go", + "reconciler_test.go", + ], embed = [":go_default_library"], deps = [ "//pkg/features:go_default_library", diff --git a/pkg/kubelet/volumemanager/reconciler/main_test.go b/pkg/kubelet/volumemanager/reconciler/main_test.go new file mode 100644 index 00000000000..e89d5ca3ea0 --- /dev/null +++ b/pkg/kubelet/volumemanager/reconciler/main_test.go @@ -0,0 +1,29 @@ +/* +Copyright 2018 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 reconciler + +import ( + "testing" + + utilfeature "k8s.io/apiserver/pkg/util/feature" + utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing" + _ "k8s.io/kubernetes/pkg/features" +) + +func TestMain(m *testing.M) { + utilfeaturetesting.VerifyFeatureGatesUnchanged(utilfeature.DefaultFeatureGate, m.Run) +} diff --git a/pkg/volume/csi/BUILD b/pkg/volume/csi/BUILD index 597fd6597a2..2bc3929fe0f 100644 --- a/pkg/volume/csi/BUILD +++ b/pkg/volume/csi/BUILD @@ -44,6 +44,7 @@ go_test( "csi_client_test.go", "csi_mounter_test.go", "csi_plugin_test.go", + "main_test.go", ], embed = [":go_default_library"], deps = [ diff --git a/pkg/volume/csi/main_test.go b/pkg/volume/csi/main_test.go new file mode 100644 index 00000000000..5322fcd7edc --- /dev/null +++ b/pkg/volume/csi/main_test.go @@ -0,0 +1,29 @@ +/* +Copyright 2018 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 csi + +import ( + "testing" + + utilfeature "k8s.io/apiserver/pkg/util/feature" + utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing" + _ "k8s.io/kubernetes/pkg/features" +) + +func TestMain(m *testing.M) { + utilfeaturetesting.VerifyFeatureGatesUnchanged(utilfeature.DefaultFeatureGate, m.Run) +} diff --git a/pkg/volume/util/BUILD b/pkg/volume/util/BUILD index ffd1d032151..64eac778de2 100644 --- a/pkg/volume/util/BUILD +++ b/pkg/volume/util/BUILD @@ -52,6 +52,7 @@ go_test( "atomic_writer_test.go", "attach_limit_test.go", "device_util_linux_test.go", + "main_test.go", "nested_volumes_test.go", "resize_util_test.go", "util_test.go", diff --git a/pkg/volume/util/main_test.go b/pkg/volume/util/main_test.go new file mode 100644 index 00000000000..6af02d0a11d --- /dev/null +++ b/pkg/volume/util/main_test.go @@ -0,0 +1,29 @@ +/* +Copyright 2018 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 util + +import ( + "testing" + + utilfeature "k8s.io/apiserver/pkg/util/feature" + utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing" + _ "k8s.io/kubernetes/pkg/features" +) + +func TestMain(m *testing.M) { + utilfeaturetesting.VerifyFeatureGatesUnchanged(utilfeature.DefaultFeatureGate, m.Run) +} diff --git a/plugin/pkg/admission/storage/persistentvolume/label/BUILD b/plugin/pkg/admission/storage/persistentvolume/label/BUILD index d93e3e75c1f..35b7366258d 100644 --- a/plugin/pkg/admission/storage/persistentvolume/label/BUILD +++ b/plugin/pkg/admission/storage/persistentvolume/label/BUILD @@ -32,7 +32,10 @@ go_library( go_test( name = "go_default_test", - srcs = ["admission_test.go"], + srcs = [ + "admission_test.go", + "main_test.go", + ], embed = [":go_default_library"], deps = [ "//pkg/apis/core:go_default_library", diff --git a/plugin/pkg/admission/storage/persistentvolume/label/main_test.go b/plugin/pkg/admission/storage/persistentvolume/label/main_test.go new file mode 100644 index 00000000000..60a5d5020e5 --- /dev/null +++ b/plugin/pkg/admission/storage/persistentvolume/label/main_test.go @@ -0,0 +1,29 @@ +/* +Copyright 2018 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 label + +import ( + "testing" + + utilfeature "k8s.io/apiserver/pkg/util/feature" + utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing" + _ "k8s.io/kubernetes/pkg/features" +) + +func TestMain(m *testing.M) { + utilfeaturetesting.VerifyFeatureGatesUnchanged(utilfeature.DefaultFeatureGate, m.Run) +} diff --git a/plugin/pkg/admission/storage/storageobjectinuseprotection/BUILD b/plugin/pkg/admission/storage/storageobjectinuseprotection/BUILD index 712b6555d56..6073526d6bc 100644 --- a/plugin/pkg/admission/storage/storageobjectinuseprotection/BUILD +++ b/plugin/pkg/admission/storage/storageobjectinuseprotection/BUILD @@ -17,7 +17,10 @@ go_library( go_test( name = "go_default_test", - srcs = ["admission_test.go"], + srcs = [ + "admission_test.go", + "main_test.go", + ], embed = [":go_default_library"], deps = [ "//pkg/apis/core:go_default_library", diff --git a/plugin/pkg/admission/storage/storageobjectinuseprotection/main_test.go b/plugin/pkg/admission/storage/storageobjectinuseprotection/main_test.go new file mode 100644 index 00000000000..1c7d89390a1 --- /dev/null +++ b/plugin/pkg/admission/storage/storageobjectinuseprotection/main_test.go @@ -0,0 +1,29 @@ +/* +Copyright 2018 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 storageobjectinuseprotection + +import ( + "testing" + + utilfeature "k8s.io/apiserver/pkg/util/feature" + utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing" + _ "k8s.io/kubernetes/pkg/features" +) + +func TestMain(m *testing.M) { + utilfeaturetesting.VerifyFeatureGatesUnchanged(utilfeature.DefaultFeatureGate, m.Run) +} diff --git a/staging/src/k8s.io/apiserver/pkg/util/feature/testing/feature_gate_testing.go b/staging/src/k8s.io/apiserver/pkg/util/feature/testing/feature_gate_testing.go index fdbd7735a01..bcae2566bc3 100644 --- a/staging/src/k8s.io/apiserver/pkg/util/feature/testing/feature_gate_testing.go +++ b/staging/src/k8s.io/apiserver/pkg/util/feature/testing/feature_gate_testing.go @@ -18,13 +18,57 @@ package testing import ( "fmt" + "os" + "strings" "testing" "k8s.io/apiserver/pkg/util/feature" ) +// VerifyFeatureGatesUnchanged ensures the provided gate does not change any values when tests() are completed. +// Intended to be placed into unit test packages that mess with feature gates. +// +// Example use: +// +// import ( +// "testing" +// +// utilfeature "k8s.io/apiserver/pkg/util/feature" +// utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing" +// _ "k8s.io/kubernetes/pkg/features" +// ) +// +// func TestMain(m *testing.M) { +// utilfeaturetesting.VerifyFeatureGatesUnchanged(utilfeature.DefaultFeatureGate, m.Run) +// } +func VerifyFeatureGatesUnchanged(gate feature.FeatureGate, tests func() int) { + originalGates := gate.DeepCopy() + originalSet := fmt.Sprint(gate) + + rc := tests() + + finalSet := fmt.Sprint(gate) + if finalSet != originalSet { + for _, kv := range strings.Split(finalSet, ",") { + k := strings.Split(kv, "=")[0] + if originalGates.Enabled(feature.Feature(k)) != gate.Enabled(feature.Feature(k)) { + fmt.Println(fmt.Sprintf("VerifyFeatureGatesUnchanged: mutated %s feature gate from %v to %v", k, originalGates.Enabled(feature.Feature(k)), gate.Enabled(feature.Feature(k)))) + rc = 1 + } + } + } + + if rc != 0 { + os.Exit(rc) + } +} + // SetFeatureGateDuringTest sets the specified gate to the specified value, and returns a function that restores the original value. // Failures to set or restore cause the test to fail. +// +// Example use: +// +// defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features., true)() func SetFeatureGateDuringTest(t *testing.T, gate feature.FeatureGate, feature feature.Feature, value bool) func() { originalValue := gate.Enabled(feature)