github.com/abayer/test-infra@v0.0.5/mungegithub/mungers/cherrypick-clear-after-merge_test.go (about)

     1  /*
     2  Copyright 2017 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 mungers
    18  
    19  import (
    20  	"regexp"
    21  	"strings"
    22  	"testing"
    23  
    24  	"github.com/golang/glog"
    25  	githubapi "github.com/google/go-github/github"
    26  	"k8s.io/test-infra/mungegithub/github"
    27  )
    28  
    29  type testLogFinder string
    30  
    31  func (lf testLogFinder) FoundLog(branch, logString string, regexSearch bool) (bool, string) {
    32  	if branch != "branch" {
    33  		glog.Fatalf("Expected branch name \"branch\", got %q.", branch)
    34  	}
    35  	if regexSearch {
    36  		if match := regexp.MustCompile("(?m)" + logString).FindString(string(lf)); match != "" {
    37  			return true, string(lf)
    38  		}
    39  	} else {
    40  		if strings.Contains(string(lf), logString) {
    41  			return true, string(lf)
    42  		}
    43  	}
    44  	return false, ""
    45  }
    46  
    47  func TestFoundByScript(t *testing.T) {
    48  	sampleLogs := `ab4109707b03616094b8ccfb9697c19bff9a4149
    49  Merge pull request #3570 from spxtr/logconsistently
    50  Make logging in splice and tot consistent with the rest.
    51  8fd41ffcf14a8621d53bdd8282835073a85beec5
    52  Merge pull request #3594 from krzyzacy/kops-url-refix
    53  append JOB_NAME to kops build path
    54  1872c306b68919592b21ca8984f4bc603e7b2e2a
    55  Make logging in splice and tot consistent with the rest.
    56  
    57  0d07f5a827c575b9f6a1c4a3c28cf02a7003e944
    58  Forgot append JOB_NAME to kops build path
    59  
    60  c8cf39417fc81c522205c0a061ceac42285e44a3
    61  Merge pull request #48791 from luxas/automated-cherry-pick-of-#48594-#48538-upstream-release-1.7
    62  Automatic merge from submit-queue
    63  
    64  Automated cherry pick of #48594 #48538
    65  
    66  Cherry pick of #48594 #48538 on release-1.7.
    67  
    68  #48594: Add node-name flag to ` + "`init`" + ` phase
    69  #48538: Add node-name flag to ` + "`join`" + ` phase
    70  753266cb7d77456c2395521bece25eca51bfedcc
    71  Merge pull request #3592 from shyamjvs/enable-logexporter
    72  Enable logexporter for gce-scale tests
    73  1ccb815bcdfc02ba972abc80dd125cdc50fe8037
    74  Enable logexporter for gce-scale tests
    75  `
    76  	c := &ClearPickAfterMerge{logs: testLogFinder(sampleLogs)}
    77  
    78  	tests := []struct {
    79  		num     int
    80  		matches bool
    81  	}{
    82  		{48538, true},
    83  		{77, false},
    84  		{48594, true},
    85  		{3570, false},
    86  		{3594, false},
    87  		{48791, false},
    88  	}
    89  	for _, test := range tests {
    90  		if test.matches != c.foundByScript(&github.MungeObject{Issue: &githubapi.Issue{Number: &test.num}}, "branch") {
    91  			var not string
    92  			if !test.matches {
    93  				not = "not "
    94  			}
    95  			t.Errorf("Error: Expected PR #%d to %sbe found in logs!", test.num, not)
    96  		}
    97  	}
    98  }