Merge pull request #61933 from hanxiaoshuai/cleanup0330

Automatic merge from submit-queue (batch tested with PRs 59035, 61933). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

add TestGeneration in customresource/etcd_test.go

**What this PR does / why we need it**:
add TestGeneration in customresource/etcd_test.go
**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #

**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue
2018-04-09 06:56:09 -07:00
committed by GitHub
4 changed files with 102 additions and 6 deletions

View File

@@ -158,6 +158,9 @@ func TestGenerationNumber(t *testing.T) {
modifiedSno.Status.ObservedGeneration = 10
ctx := genericapirequest.NewDefaultContext()
rs, err := createReplicaSet(storage.ReplicaSet, modifiedSno, t)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
etcdRS, err := storage.ReplicaSet.Get(ctx, rs.Name, &metav1.GetOptions{})
if err != nil {
t.Errorf("unexpected error: %v", err)
@@ -165,14 +168,13 @@ func TestGenerationNumber(t *testing.T) {
storedRS, _ := etcdRS.(*extensions.ReplicaSet)
// Generation initialization
if storedRS.Generation != 1 && storedRS.Status.ObservedGeneration != 0 {
if storedRS.Generation != 1 || storedRS.Status.ObservedGeneration != 0 {
t.Fatalf("Unexpected generation number %v, status generation %v", storedRS.Generation, storedRS.Status.ObservedGeneration)
}
// Updates to spec should increment the generation number
storedRS.Spec.Replicas += 1
storage.ReplicaSet.Update(ctx, storedRS.Name, rest.DefaultUpdatedObjectInfo(storedRS), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc)
if err != nil {
if _, _, err := storage.ReplicaSet.Update(ctx, storedRS.Name, rest.DefaultUpdatedObjectInfo(storedRS), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc); err != nil {
t.Errorf("unexpected error: %v", err)
}
etcdRS, err = storage.ReplicaSet.Get(ctx, rs.Name, &metav1.GetOptions{})
@@ -186,8 +188,7 @@ func TestGenerationNumber(t *testing.T) {
// Updates to status should not increment either spec or status generation numbers
storedRS.Status.Replicas += 1
storage.ReplicaSet.Update(ctx, storedRS.Name, rest.DefaultUpdatedObjectInfo(storedRS), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc)
if err != nil {
if _, _, err := storage.ReplicaSet.Update(ctx, storedRS.Name, rest.DefaultUpdatedObjectInfo(storedRS), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc); err != nil {
t.Errorf("unexpected error: %v", err)
}
etcdRS, err = storage.ReplicaSet.Get(ctx, rs.Name, &metav1.GetOptions{})

View File

@@ -161,6 +161,9 @@ func TestGenerationNumber(t *testing.T) {
modifiedSno.Status.ObservedGeneration = 10
ctx := genericapirequest.NewDefaultContext()
rc, err := createController(storage.Controller, modifiedSno, t)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
ctrl, err := storage.Controller.Get(ctx, rc.Name, &metav1.GetOptions{})
if err != nil {
t.Errorf("unexpected error: %v", err)
@@ -168,7 +171,7 @@ func TestGenerationNumber(t *testing.T) {
controller, _ := ctrl.(*api.ReplicationController)
// Generation initialization
if controller.Generation != 1 && controller.Status.ObservedGeneration != 0 {
if controller.Generation != 1 || controller.Status.ObservedGeneration != 0 {
t.Fatalf("Unexpected generation number %v, status generation %v", controller.Generation, controller.Status.ObservedGeneration)
}