...

Source file src/k8s.io/kubernetes/pkg/controller/job/utils_test.go

Documentation: k8s.io/kubernetes/pkg/controller/job

     1  /*
     2  Copyright 2016 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package job
    18  
    19  import (
    20  	"testing"
    21  
    22  	batch "k8s.io/api/batch/v1"
    23  	"k8s.io/api/core/v1"
    24  )
    25  
    26  func TestIsJobFinished(t *testing.T) {
    27  	testCases := map[string]struct {
    28  		conditionType        batch.JobConditionType
    29  		conditionStatus      v1.ConditionStatus
    30  		expectJobNotFinished bool
    31  	}{
    32  		"Job is completed and condition is true": {
    33  			batch.JobComplete,
    34  			v1.ConditionTrue,
    35  			false,
    36  		},
    37  		"Job is completed and condition is false": {
    38  			batch.JobComplete,
    39  			v1.ConditionFalse,
    40  			true,
    41  		},
    42  		"Job is completed and condition is unknown": {
    43  			batch.JobComplete,
    44  			v1.ConditionUnknown,
    45  			true,
    46  		},
    47  		"Job is failed and condition is true": {
    48  			batch.JobFailed,
    49  			v1.ConditionTrue,
    50  			false,
    51  		},
    52  		"Job is failed and condition is false": {
    53  			batch.JobFailed,
    54  			v1.ConditionFalse,
    55  			true,
    56  		},
    57  		"Job is failed and condition is unknown": {
    58  			batch.JobFailed,
    59  			v1.ConditionUnknown,
    60  			true,
    61  		},
    62  	}
    63  
    64  	for name, tc := range testCases {
    65  		job := &batch.Job{
    66  			Status: batch.JobStatus{
    67  				Conditions: []batch.JobCondition{{
    68  					Type:   tc.conditionType,
    69  					Status: tc.conditionStatus,
    70  				}},
    71  			},
    72  		}
    73  
    74  		if tc.expectJobNotFinished == IsJobFinished(job) {
    75  			if tc.expectJobNotFinished {
    76  				t.Errorf("test name: %s, job was not expected to be finished", name)
    77  			} else {
    78  				t.Errorf("test name: %s, job was expected to be finished", name)
    79  			}
    80  		}
    81  	}
    82  }
    83  

View as plain text