Repository: kubernetes/kubernetes
File: test/integration/etcd/etcd_storage_path_test.go (Go)

Code before:
// this should only contain custom resources and built-in types with open issues tracking adding serialization fixtures.
// Do not add new built-in types to this list, add them to k8s.io/api/roundtrip_test.go instead.
var allowMissingTestdataFixtures = map[schema.GroupVersionKind]bool{
	// TODO(https://github.com/kubernetes/kubernetes/issues/79027)
	gvk("apiregistration.k8s.io", "v1", "APIService"):     true,
	gvk("apiregistration.k8s.io", "v1beta", "APIService"): true,

	// TODO(https://github.com/kubernetes/kubernetes/issues/79026)
	gvk("apiextensions.k8s.io", "v1beta1", "CustomResourceDefinition"): true,
	gvk("apiextensions.k8s.io", "v1", "CustomResourceDefinition"):      true,

	// Custom resources are not expected to have serialization fixtures in k8s.io/api
	gvk("awesome.bears.com", "v1", "Panda"):    true,
	gvk("cr.bar.com", "v1", "Foo"):             true,
	gvk("random.numbers.com", "v1", "Integer"): true,
	gvk("custom.fancy.com", "v2", "Pant"):      true,
}

// TestEtcdStoragePath tests to make sure that all objects are stored in an expected location in etcd.
// It will start failing when a new type is added to ensure that all future types are added to this test.
// It will also fail when a type gets moved to a different location. Be very careful in this situation because
// it essentially means that you will be break old clusters unless you create some migration path for the old data.
func TestEtcdStoragePath(t *testing.T) {
	supportedVersions := GetSupportedEmulatedVersions()
	for _, v := range supportedVersions {
		testEtcdStoragePathWithVersion(t, v)
	}
}

func testEtcdStoragePathWithVersion(t *testing.T, v string) {
	if v == componentbaseversion.DefaultKubeBinaryVersion {
		featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, "AllAlpha", true)
		featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, "AllBeta", true)
	} else {
		// Only test for beta and GA APIs with emulated version.
		featuregatetesting.SetFeatureGateEmulationVersionDuringTest(t, feature.DefaultFeatureGate, version.MustParse(v))
		featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, "AllBeta", true)
		registerEffectiveEmulationVersion(t)
	}

	apiServer := StartRealAPIServerOrDie(t, func(opts *options.ServerRunOptions) {
		// Disable alphas when emulating previous versions.
		if v != componentbaseversion.DefaultKubeBinaryVersion {
			opts.Options.APIEnablement.RuntimeConfig["api/alpha"] = "false"
		}
	})

	defer apiServer.Cleanup()
	defer dumpEtcdKVOnFailure(t, apiServer.KV)

	client := &allClient{dynamicClient: apiServer.Dynamic}

Review comment (suggestion):
nit: make a subtest to separate results
```suggestion
		t.Run(v, func(t *testing.T) {
			testEtcdStoragePathWithVersion(t, v)
		})
```

Code after:
// this should only contain custom resources and built-in types with open issues tracking adding serialization fixtures.
// Do not add new built-in types to this list, add them to k8s.io/api/roundtrip_test.go instead.
var allowMissingTestdataFixtures = map[schema.GroupVersionKind]bool{
	// TODO(https://github.com/kubernetes/kubernetes/issues/79027)
	gvk("apiregistration.k8s.io", "v1", "APIService"):     true,
	gvk("apiregistration.k8s.io", "v1beta", "APIService"): true,

	// TODO(https://github.com/kubernetes/kubernetes/issues/79026)
	gvk("apiextensions.k8s.io", "v1beta1", "CustomResourceDefinition"): true,
	gvk("apiextensions.k8s.io", "v1", "CustomResourceDefinition"):      true,

	// Custom resources are not expected to have serialization fixtures in k8s.io/api
	gvk("awesome.bears.com", "v1", "Panda"):    true,
	gvk("cr.bar.com", "v1", "Foo"):             true,
	gvk("random.numbers.com", "v1", "Integer"): true,
	gvk("custom.fancy.com", "v2", "Pant"):      true,
}

// TestEtcdStoragePath tests to make sure that all objects are stored in an expected location in etcd.
// It will start failing when a new type is added to ensure that all future types are added to this test.
// It will also fail when a type gets moved to a different location. Be very careful in this situation because
// it essentially means that you will be break old clusters unless you create some migration path for the old data.
func TestEtcdStoragePath(t *testing.T) {
	supportedVersions := GetSupportedEmulatedVersions()
	for _, v := range supportedVersions {
		t.Run(v, func(t *testing.T) {
			testEtcdStoragePathWithVersion(t, v)
		})
	}
}

func testEtcdStoragePathWithVersion(t *testing.T, v string) {
	if v == componentbaseversion.DefaultKubeBinaryVersion {
		featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, "AllAlpha", true)
		featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, "AllBeta", true)
	} else {
		// Only test for beta and GA APIs with emulated version.
		featuregatetesting.SetFeatureGateEmulationVersionDuringTest(t, feature.DefaultFeatureGate, version.MustParse(v))
		featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, "AllBeta", true)
		registerEffectiveEmulationVersion(t)
	}

	apiServer := StartRealAPIServerOrDie(t, func(opts *options.ServerRunOptions) {
		// Disable alphas when emulating previous versions.
		if v != componentbaseversion.DefaultKubeBinaryVersion {
			opts.Options.APIEnablement.RuntimeConfig["api/alpha"] = "false"
		}
	})

	defer apiServer.Cleanup()
	defer dumpEtcdKVOnFailure(t, apiServer.KV)