mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Add unit test for JobUpdateStatus and fix erroneous test for DaemonSetStatusUpdate
This commit is contained in:
		@@ -354,11 +354,14 @@ func TestValidateDaemonSetStatusUpdate(t *testing.T) {
 | 
				
			|||||||
			t.Errorf("expected success: %v", errs)
 | 
								t.Errorf("expected success: %v", errs)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	errorCases := map[string]dsUpdateTest{
 | 
						errorCases := map[string]dsUpdateTest{
 | 
				
			||||||
		"negative values": {
 | 
							"negative values": {
 | 
				
			||||||
			old: extensions.DaemonSet{
 | 
								old: extensions.DaemonSet{
 | 
				
			||||||
				ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: api.NamespaceDefault},
 | 
									ObjectMeta: api.ObjectMeta{
 | 
				
			||||||
 | 
										Name:            "abc",
 | 
				
			||||||
 | 
										Namespace:       api.NamespaceDefault,
 | 
				
			||||||
 | 
										ResourceVersion: "10",
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
				Status: extensions.DaemonSetStatus{
 | 
									Status: extensions.DaemonSetStatus{
 | 
				
			||||||
					CurrentNumberScheduled: 1,
 | 
										CurrentNumberScheduled: 1,
 | 
				
			||||||
					NumberMisscheduled:     2,
 | 
										NumberMisscheduled:     2,
 | 
				
			||||||
@@ -366,7 +369,11 @@ func TestValidateDaemonSetStatusUpdate(t *testing.T) {
 | 
				
			|||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			update: extensions.DaemonSet{
 | 
								update: extensions.DaemonSet{
 | 
				
			||||||
				ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: api.NamespaceDefault},
 | 
									ObjectMeta: api.ObjectMeta{
 | 
				
			||||||
 | 
										Name:            "abc",
 | 
				
			||||||
 | 
										Namespace:       api.NamespaceDefault,
 | 
				
			||||||
 | 
										ResourceVersion: "10",
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
				Status: extensions.DaemonSetStatus{
 | 
									Status: extensions.DaemonSetStatus{
 | 
				
			||||||
					CurrentNumberScheduled: -1,
 | 
										CurrentNumberScheduled: -1,
 | 
				
			||||||
					NumberMisscheduled:     -1,
 | 
										NumberMisscheduled:     -1,
 | 
				
			||||||
@@ -377,7 +384,7 @@ func TestValidateDaemonSetStatusUpdate(t *testing.T) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for testName, errorCase := range errorCases {
 | 
						for testName, errorCase := range errorCases {
 | 
				
			||||||
		if errs := ValidateDaemonSetStatusUpdate(&errorCase.old, &errorCase.update); len(errs) == 0 {
 | 
							if errs := ValidateDaemonSetStatusUpdate(&errorCase.update, &errorCase.old); len(errs) == 0 {
 | 
				
			||||||
			t.Errorf("expected failure: %s", testName)
 | 
								t.Errorf("expected failure: %s", testName)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -1163,6 +1170,82 @@ func TestValidateJob(t *testing.T) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestValidateJobUpdateStatus(t *testing.T) {
 | 
				
			||||||
 | 
						type testcase struct {
 | 
				
			||||||
 | 
							old    extensions.Job
 | 
				
			||||||
 | 
							update extensions.Job
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						successCases := []testcase{
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								old: extensions.Job{
 | 
				
			||||||
 | 
									ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: api.NamespaceDefault},
 | 
				
			||||||
 | 
									Status: extensions.JobStatus{
 | 
				
			||||||
 | 
										Active:    1,
 | 
				
			||||||
 | 
										Succeeded: 2,
 | 
				
			||||||
 | 
										Failed:    3,
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								update: extensions.Job{
 | 
				
			||||||
 | 
									ObjectMeta: api.ObjectMeta{Name: "abc", Namespace: api.NamespaceDefault},
 | 
				
			||||||
 | 
									Status: extensions.JobStatus{
 | 
				
			||||||
 | 
										Active:    1,
 | 
				
			||||||
 | 
										Succeeded: 1,
 | 
				
			||||||
 | 
										Failed:    3,
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, successCase := range successCases {
 | 
				
			||||||
 | 
							successCase.old.ObjectMeta.ResourceVersion = "1"
 | 
				
			||||||
 | 
							successCase.update.ObjectMeta.ResourceVersion = "1"
 | 
				
			||||||
 | 
							if errs := ValidateJobUpdateStatus(&successCase.update, &successCase.old); len(errs) != 0 {
 | 
				
			||||||
 | 
								t.Errorf("expected success: %v", errs)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						errorCases := map[string]testcase{
 | 
				
			||||||
 | 
							"[status.active: Invalid value: -1: must be greater than or equal to 0, status.succeeded: Invalid value: -2: must be greater than or equal to 0]": {
 | 
				
			||||||
 | 
								old: extensions.Job{
 | 
				
			||||||
 | 
									ObjectMeta: api.ObjectMeta{
 | 
				
			||||||
 | 
										Name:            "abc",
 | 
				
			||||||
 | 
										Namespace:       api.NamespaceDefault,
 | 
				
			||||||
 | 
										ResourceVersion: "10",
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									Status: extensions.JobStatus{
 | 
				
			||||||
 | 
										Active:    1,
 | 
				
			||||||
 | 
										Succeeded: 2,
 | 
				
			||||||
 | 
										Failed:    3,
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								update: extensions.Job{
 | 
				
			||||||
 | 
									ObjectMeta: api.ObjectMeta{
 | 
				
			||||||
 | 
										Name:            "abc",
 | 
				
			||||||
 | 
										Namespace:       api.NamespaceDefault,
 | 
				
			||||||
 | 
										ResourceVersion: "10",
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									Status: extensions.JobStatus{
 | 
				
			||||||
 | 
										Active:    -1,
 | 
				
			||||||
 | 
										Succeeded: -2,
 | 
				
			||||||
 | 
										Failed:    3,
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for testName, errorCase := range errorCases {
 | 
				
			||||||
 | 
							errs := ValidateJobUpdateStatus(&errorCase.update, &errorCase.old)
 | 
				
			||||||
 | 
							if len(errs) == 0 {
 | 
				
			||||||
 | 
								t.Errorf("expected failure: %s", testName)
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if errs.ToAggregate().Error() != testName {
 | 
				
			||||||
 | 
								t.Errorf("expected '%s' got '%s'", errs.ToAggregate().Error(), testName)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type ingressRules map[string]string
 | 
					type ingressRules map[string]string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestValidateIngress(t *testing.T) {
 | 
					func TestValidateIngress(t *testing.T) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user