Repository: kubernetes/kubernetes
File: staging/src/k8s.io/client-go/features/testing/features.go (Go)

Code before:
	defer overriddenFeaturesLock.Unlock()

	currentFeatureGates := clientfeatures.FeatureGates()
	featureGates, ok := currentFeatureGates.(featureGatesSetter)
	if !ok {
		panic(fmt.Errorf("clientfeatures.FeatureGates(): %T does not implement featureGatesSetter interface", currentFeatureGates))
	}

	originalFeatureValue := featureGates.Enabled(feature)
	if overridingTestName, ok := overriddenFeatures[feature]; ok {
		if !sameTestOrSubtest(tb, overridingTestName) {
			return fmt.Errorf("client-go feature %q is currently overridden by %q test and cannot be also modified by %q", feature, overridingTestName, tb.Name())
		}
	}

	setFeature := func(feature clientfeatures.Feature, featureValue bool) error {
		if testSetter, ok := featureGates.(featureGatesSetterForTesting); ok {
			if err := testSetter.SetForTesting(feature, featureValue); err != nil {
				return err
			}
		} else {
			if err := featureGates.Set(feature, featureValue); err != nil {
				return err
			}
		}
		return nil
	}

	if err := setFeature(feature, featureValue); err != nil {
		return err
	}

	overriddenFeatures[feature] = tb.Name()

	tb.Cleanup(func() {
		overriddenFeaturesLock.Lock()
		defer overriddenFeaturesLock.Unlock()
		delete(overriddenFeatures, feature)
		// if default is not set
		if err := setFeature(feature, originalFeatureValue); err != nil {
			tb.Errorf("failed restoring client-go feature: %v to its original value: %v, err: %v", feature, originalFeatureValue, err)
		}
	})
	return nil
}

// copied from component-base/featuregate/testing
func sameTestOrSubtest(tb testing.TB, testName string) bool {
	return tb.Name() == testName || strings.HasPrefix(tb.Name(), testName+"/")
}


Review comment (suggestion):
```suggestion
		}
		return featureGates.Set(feature, featureValue)
```

Code after:
	defer overriddenFeaturesLock.Unlock()

	currentFeatureGates := clientfeatures.FeatureGates()
	featureGates, ok := currentFeatureGates.(featureGatesSetter)
	if !ok {
		panic(fmt.Errorf("clientfeatures.FeatureGates(): %T does not implement featureGatesSetter interface", currentFeatureGates))
	}

	originalFeatureValue := featureGates.Enabled(feature)
	if overridingTestName, ok := overriddenFeatures[feature]; ok {
		if !sameTestOrSubtest(tb, overridingTestName) {
			return fmt.Errorf("client-go feature %q is currently overridden by %q test and cannot be also modified by %q", feature, overridingTestName, tb.Name())
		}
	}

	setFeature := func(feature clientfeatures.Feature, featureValue bool) error {
		if testSetter, ok := featureGates.(featureGatesSetterForTesting); ok {
			return testSetter.SetForTesting(feature, featureValue)
		}
		return featureGates.Set(feature, featureValue)
	}

	if err := setFeature(feature, featureValue); err != nil {
		return err
	}

	overriddenFeatures[feature] = tb.Name()

	tb.Cleanup(func() {
		overriddenFeaturesLock.Lock()
		defer overriddenFeaturesLock.Unlock()
		delete(overriddenFeatures, feature)
		// if default is not set
		if err := setFeature(feature, originalFeatureValue); err != nil {
			tb.Errorf("failed restoring client-go feature: %v to its original value: %v, err: %v", feature, originalFeatureValue, err)
		}
	})
	return nil
}

// copied from component-base/featuregate/testing
func sameTestOrSubtest(tb testing.TB, testName string) bool {
	return tb.Name() == testName || strings.HasPrefix(tb.Name(), testName+"/")
}