github.com/munnerz/test-infra@v0.0.0-20190108210205-ce3d181dc989/prow/github/reporter/reporter_test.go (about)

     1  /*
     2  Copyright 2018 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 reporter
    18  
    19  import (
    20  	"testing"
    21  
    22  	"k8s.io/test-infra/prow/apis/prowjobs/v1"
    23  )
    24  
    25  func TestShouldReport(t *testing.T) {
    26  	var testcases = []struct {
    27  		name   string
    28  		pj     *v1.ProwJob
    29  		report bool
    30  	}{
    31  		{
    32  			name: "should not report skip report job",
    33  			pj: &v1.ProwJob{
    34  				Spec: v1.ProwJobSpec{
    35  					Type:   v1.PresubmitJob,
    36  					Report: false,
    37  				},
    38  			},
    39  			report: false,
    40  		},
    41  		{
    42  			name: "should not report periodic job",
    43  			pj: &v1.ProwJob{
    44  				Spec: v1.ProwJobSpec{
    45  					Type:   v1.PeriodicJob,
    46  					Report: true,
    47  				},
    48  			},
    49  			report: false,
    50  		},
    51  		{
    52  			name: "should not report postsubmit job",
    53  			pj: &v1.ProwJob{
    54  				Spec: v1.ProwJobSpec{
    55  					Type:   v1.PostsubmitJob,
    56  					Report: true,
    57  				},
    58  			},
    59  			report: false,
    60  		},
    61  		{
    62  			name: "should not report batch job",
    63  			pj: &v1.ProwJob{
    64  				Spec: v1.ProwJobSpec{
    65  					Type:   v1.BatchJob,
    66  					Report: true,
    67  				},
    68  			},
    69  			report: false,
    70  		},
    71  		{
    72  			name: "only report presubmit job",
    73  			pj: &v1.ProwJob{
    74  				Spec: v1.ProwJobSpec{
    75  					Type:   v1.PresubmitJob,
    76  					Report: true,
    77  				},
    78  			},
    79  			report: true,
    80  		},
    81  	}
    82  
    83  	c := NewReporter(nil, nil)
    84  
    85  	for _, tc := range testcases {
    86  		r := c.ShouldReport(tc.pj)
    87  
    88  		if r != tc.report {
    89  			t.Errorf("Unexpected result from test: %s.\nExpected: %v\nGot: %v",
    90  				tc.name, tc.report, r)
    91  		}
    92  	}
    93  }