PetSet replica count status test
This commit is contained in:
@@ -25,6 +25,9 @@ import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/apis/apps"
|
||||
"k8s.io/kubernetes/pkg/client/cache"
|
||||
fake_internal "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
|
||||
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/apps/unversioned"
|
||||
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/apps/unversioned/fake"
|
||||
"k8s.io/kubernetes/pkg/controller"
|
||||
"k8s.io/kubernetes/pkg/util/errors"
|
||||
)
|
||||
@@ -268,8 +271,7 @@ func TestPetSetBlockingPetIsCleared(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(mkwiek): test if the petset.Status.Replicas is actually correct
|
||||
func TestPetSetReplicaCount(t *testing.T) {
|
||||
func TestSyncPetSetBlockedPet(t *testing.T) {
|
||||
psc, fc := newFakePetSetController()
|
||||
ps := newPetSet(3)
|
||||
i, _ := psc.syncPetSet(ps, fc.getPodList())
|
||||
@@ -277,3 +279,53 @@ func TestPetSetReplicaCount(t *testing.T) {
|
||||
t.Errorf("syncPetSet should return actual amount of pods")
|
||||
}
|
||||
}
|
||||
|
||||
type fakeClient struct {
|
||||
fake_internal.Clientset
|
||||
petSetClient *fakePetSetClient
|
||||
}
|
||||
|
||||
func (c *fakeClient) Apps() unversioned.AppsInterface {
|
||||
return &fakeApps{c, &fake.FakeApps{}}
|
||||
}
|
||||
|
||||
type fakeApps struct {
|
||||
*fakeClient
|
||||
*fake.FakeApps
|
||||
}
|
||||
|
||||
func (c *fakeApps) PetSets(namespace string) unversioned.PetSetInterface {
|
||||
c.petSetClient.Namespace = namespace
|
||||
return c.petSetClient
|
||||
}
|
||||
|
||||
type fakePetSetClient struct {
|
||||
*fake.FakePetSets
|
||||
Namespace string
|
||||
replicas int
|
||||
}
|
||||
|
||||
func (f *fakePetSetClient) UpdateStatus(petSet *apps.PetSet) (*apps.PetSet, error) {
|
||||
f.replicas = petSet.Status.Replicas
|
||||
return petSet, nil
|
||||
}
|
||||
|
||||
func TestPetSetReplicaCount(t *testing.T) {
|
||||
fpsc := &fakePetSetClient{}
|
||||
psc, _ := newFakePetSetController()
|
||||
psc.kubeClient = &fakeClient{
|
||||
petSetClient: fpsc,
|
||||
}
|
||||
|
||||
ps := newPetSet(3)
|
||||
psKey := fmt.Sprintf("%v/%v", ps.Namespace, ps.Name)
|
||||
psc.psStore.Store.Add(ps)
|
||||
|
||||
if err := psc.Sync(psKey); err != nil {
|
||||
t.Errorf("Error during sync of deleted petset %v", err)
|
||||
}
|
||||
|
||||
if fpsc.replicas != 1 {
|
||||
t.Errorf("Replicas count sent as status update for PetSet should be 1, is %d instead", fpsc.replicas)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user