Commit 8e22dc06 authored by Maru Newby's avatar Maru Newby

fed: Factor common setup for crud testing into helper function

parent ee5dbf10
...@@ -20,6 +20,7 @@ go_test( ...@@ -20,6 +20,7 @@ go_test(
deps = [ deps = [
"//federation/apis/federation/v1beta1:go_default_library", "//federation/apis/federation/v1beta1:go_default_library",
"//federation/pkg/federatedtypes:go_default_library", "//federation/pkg/federatedtypes:go_default_library",
"//federation/pkg/federatedtypes/crudtester:go_default_library",
"//pkg/api/v1:go_default_library", "//pkg/api/v1:go_default_library",
"//pkg/apis/autoscaling/v1:go_default_library", "//pkg/apis/autoscaling/v1:go_default_library",
"//pkg/apis/batch/v1:go_default_library", "//pkg/apis/batch/v1:go_default_library",
...@@ -28,6 +29,7 @@ go_test( ...@@ -28,6 +29,7 @@ go_test(
"//vendor/github.com/pborman/uuid:go_default_library", "//vendor/github.com/pborman/uuid:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library", "//vendor/github.com/stretchr/testify/assert:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
], ],
) )
......
...@@ -22,7 +22,9 @@ import ( ...@@ -22,7 +22,9 @@ import (
"github.com/pborman/uuid" "github.com/pborman/uuid"
pkgruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubernetes/federation/pkg/federatedtypes" "k8s.io/kubernetes/federation/pkg/federatedtypes"
"k8s.io/kubernetes/federation/pkg/federatedtypes/crudtester"
"k8s.io/kubernetes/test/integration/federation/framework" "k8s.io/kubernetes/test/integration/federation/framework"
) )
...@@ -35,16 +37,10 @@ func TestFederationCRUD(t *testing.T) { ...@@ -35,16 +37,10 @@ func TestFederationCRUD(t *testing.T) {
federatedTypes := federatedtypes.FederatedTypes() federatedTypes := federatedtypes.FederatedTypes()
for kind, fedType := range federatedTypes { for kind, fedType := range federatedTypes {
t.Run(kind, func(t *testing.T) { t.Run(kind, func(t *testing.T) {
config := fedFixture.APIFixture.NewConfig() fixture, crudTester, obj := initCRUDTest(t, &fedFixture, fedType.AdapterFactory, kind)
fixture := framework.NewControllerFixture(t, kind, fedType.AdapterFactory, config)
defer fixture.TearDown(t) defer fixture.TearDown(t)
client := fedFixture.APIFixture.NewClient(fmt.Sprintf("crud-test-%s", kind)) crudTester.CheckLifecycle(obj)
adapter := fedType.AdapterFactory(client)
crudtester := framework.NewFederatedTypeCRUDTester(t, adapter, fedFixture.ClusterClients)
obj := adapter.NewTestObject(uuid.New())
crudtester.CheckLifecycle(obj)
}) })
} }
...@@ -60,35 +56,38 @@ func TestFederationCRUD(t *testing.T) { ...@@ -60,35 +56,38 @@ func TestFederationCRUD(t *testing.T) {
} }
for testName, orphanDependents := range testCases { for testName, orphanDependents := range testCases {
t.Run(testName, func(t *testing.T) { t.Run(testName, func(t *testing.T) {
config := fedFixture.APIFixture.NewConfig() fixture, crudTester, obj := initCRUDTest(t, &fedFixture, adapterFactory, kind)
fixture := framework.NewControllerFixture(t, kind, adapterFactory, config)
defer fixture.TearDown(t) defer fixture.TearDown(t)
client := fedFixture.APIFixture.NewClient(fmt.Sprintf("deletion-test-%s", kind)) updatedObj := crudTester.CheckCreate(obj)
adapter := adapterFactory(client) crudTester.CheckDelete(updatedObj, orphanDependents)
crudtester := framework.NewFederatedTypeCRUDTester(t, adapter, fedFixture.ClusterClients)
obj := adapter.NewTestObject(uuid.New())
updatedObj := crudtester.CheckCreate(obj)
crudtester.CheckDelete(updatedObj, orphanDependents)
}) })
} }
t.Run("Resource should be propagated to a newly added cluster", func(t *testing.T) { t.Run("Resource should be propagated to a newly added cluster", func(t *testing.T) {
fixture, crudTester, obj := initCRUDTest(t, &fedFixture, adapterFactory, kind)
defer fixture.TearDown(t)
updatedObj := crudTester.CheckCreate(obj)
// Start a new cluster and validate that the resource is propagated to it.
fedFixture.StartCluster(t)
// Check propagation to the new cluster by providing the updated set of clients
crudTester.CheckPropagationForClients(updatedObj, fedFixture.ClusterClients)
})
}
// initCRUDTest initializes common elements of a crud test
func initCRUDTest(t *testing.T, fedFixture *framework.FederationFixture, adapterFactory federatedtypes.AdapterFactory, kind string) (
*framework.ControllerFixture, *crudtester.FederatedTypeCRUDTester, pkgruntime.Object) {
config := fedFixture.APIFixture.NewConfig() config := fedFixture.APIFixture.NewConfig()
fixture := framework.NewControllerFixture(t, kind, adapterFactory, config) fixture := framework.NewControllerFixture(t, kind, adapterFactory, config)
defer fixture.TearDown(t)
client := fedFixture.APIFixture.NewClient(fmt.Sprintf("cluster-addition-test-%s", kind)) client := fedFixture.APIFixture.NewClient(fmt.Sprintf("crud-test-%s", kind))
adapter := adapterFactory(client) adapter := adapterFactory(client)
crudtester := framework.NewFederatedTypeCRUDTester(t, adapter, fedFixture.ClusterClients) crudTester := framework.NewFederatedTypeCRUDTester(t, adapter, fedFixture.ClusterClients)
obj := adapter.NewTestObject(uuid.New()) obj := adapter.NewTestObject(uuid.New())
updatedObj := crudtester.CheckCreate(obj)
// Start a new cluster and validate that the resource is propagated to it. return fixture, crudTester, obj
fedFixture.StartCluster(t)
// Check propagation to the new cluster by providing the updated set of clients
crudtester.CheckPropagationForClients(updatedObj, fedFixture.ClusterClients)
})
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment