mirror of https://github.com/k3s-io/k3s
fed: Factor common setup for crud testing into helper function
parent
ee5dbf103e
commit
8e22dc0600
|
@ -20,6 +20,7 @@ go_test(
|
|||
deps = [
|
||||
"//federation/apis/federation/v1beta1:go_default_library",
|
||||
"//federation/pkg/federatedtypes:go_default_library",
|
||||
"//federation/pkg/federatedtypes/crudtester:go_default_library",
|
||||
"//pkg/api/v1:go_default_library",
|
||||
"//pkg/apis/autoscaling/v1:go_default_library",
|
||||
"//pkg/apis/batch/v1:go_default_library",
|
||||
|
@ -28,6 +29,7 @@ go_test(
|
|||
"//vendor/github.com/pborman/uuid: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/runtime:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||
],
|
||||
)
|
||||
|
|
|
@ -22,7 +22,9 @@ import (
|
|||
|
||||
"github.com/pborman/uuid"
|
||||
|
||||
pkgruntime "k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/kubernetes/federation/pkg/federatedtypes"
|
||||
"k8s.io/kubernetes/federation/pkg/federatedtypes/crudtester"
|
||||
"k8s.io/kubernetes/test/integration/federation/framework"
|
||||
)
|
||||
|
||||
|
@ -35,16 +37,10 @@ func TestFederationCRUD(t *testing.T) {
|
|||
federatedTypes := federatedtypes.FederatedTypes()
|
||||
for kind, fedType := range federatedTypes {
|
||||
t.Run(kind, func(t *testing.T) {
|
||||
config := fedFixture.APIFixture.NewConfig()
|
||||
fixture := framework.NewControllerFixture(t, kind, fedType.AdapterFactory, config)
|
||||
fixture, crudTester, obj := initCRUDTest(t, &fedFixture, fedType.AdapterFactory, kind)
|
||||
defer fixture.TearDown(t)
|
||||
|
||||
client := fedFixture.APIFixture.NewClient(fmt.Sprintf("crud-test-%s", kind))
|
||||
adapter := fedType.AdapterFactory(client)
|
||||
|
||||
crudtester := framework.NewFederatedTypeCRUDTester(t, adapter, fedFixture.ClusterClients)
|
||||
obj := adapter.NewTestObject(uuid.New())
|
||||
crudtester.CheckLifecycle(obj)
|
||||
crudTester.CheckLifecycle(obj)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -60,35 +56,38 @@ func TestFederationCRUD(t *testing.T) {
|
|||
}
|
||||
for testName, orphanDependents := range testCases {
|
||||
t.Run(testName, func(t *testing.T) {
|
||||
config := fedFixture.APIFixture.NewConfig()
|
||||
fixture := framework.NewControllerFixture(t, kind, adapterFactory, config)
|
||||
fixture, crudTester, obj := initCRUDTest(t, &fedFixture, adapterFactory, kind)
|
||||
defer fixture.TearDown(t)
|
||||
|
||||
client := fedFixture.APIFixture.NewClient(fmt.Sprintf("deletion-test-%s", kind))
|
||||
adapter := adapterFactory(client)
|
||||
|
||||
crudtester := framework.NewFederatedTypeCRUDTester(t, adapter, fedFixture.ClusterClients)
|
||||
obj := adapter.NewTestObject(uuid.New())
|
||||
updatedObj := crudtester.CheckCreate(obj)
|
||||
crudtester.CheckDelete(updatedObj, orphanDependents)
|
||||
updatedObj := crudTester.CheckCreate(obj)
|
||||
crudTester.CheckDelete(updatedObj, orphanDependents)
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("Resource should be propagated to a newly added cluster", func(t *testing.T) {
|
||||
config := fedFixture.APIFixture.NewConfig()
|
||||
fixture := framework.NewControllerFixture(t, kind, adapterFactory, config)
|
||||
fixture, crudTester, obj := initCRUDTest(t, &fedFixture, adapterFactory, kind)
|
||||
defer fixture.TearDown(t)
|
||||
|
||||
client := fedFixture.APIFixture.NewClient(fmt.Sprintf("cluster-addition-test-%s", kind))
|
||||
adapter := adapterFactory(client)
|
||||
|
||||
crudtester := framework.NewFederatedTypeCRUDTester(t, adapter, fedFixture.ClusterClients)
|
||||
obj := adapter.NewTestObject(uuid.New())
|
||||
updatedObj := crudtester.CheckCreate(obj)
|
||||
|
||||
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)
|
||||
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()
|
||||
fixture := framework.NewControllerFixture(t, kind, adapterFactory, config)
|
||||
|
||||
client := fedFixture.APIFixture.NewClient(fmt.Sprintf("crud-test-%s", kind))
|
||||
adapter := adapterFactory(client)
|
||||
|
||||
crudTester := framework.NewFederatedTypeCRUDTester(t, adapter, fedFixture.ClusterClients)
|
||||
|
||||
obj := adapter.NewTestObject(uuid.New())
|
||||
|
||||
return fixture, crudTester, obj
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue