github.com/abayer/test-infra@v0.0.5/velodrome/transform/plugins/author_filter_wrapper_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 plugins
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/golang/mock/gomock"
    23  	"k8s.io/test-infra/velodrome/sql"
    24  )
    25  
    26  // We ignore everything coming from specified people.
    27  func TestAuthorFilterIssues(t *testing.T) {
    28  	ctrl := gomock.NewController(t)
    29  	defer ctrl.Finish()
    30  
    31  	plugin := NewMockPlugin(ctrl)
    32  	authorFilter := NewAuthorFilterPluginWrapper(plugin)
    33  	authorFilter.ignoredAuthors = []string{"OneBot", "OtherBot"}
    34  
    35  	plugin.EXPECT().ReceiveIssue(sql.Issue{ID: "2", User: "Person"}).Return([]Point{{}})
    36  
    37  	if p := authorFilter.ReceiveIssue(sql.Issue{ID: "1", User: "OneBot"}); len(p) != 0 {
    38  		t.Error("OneBot issues should be filtered")
    39  	}
    40  	if p := authorFilter.ReceiveIssue(sql.Issue{ID: "2", User: "Person"}); len(p) != 1 {
    41  		t.Error("Person issues shouldn't be filtered")
    42  	}
    43  	if p := authorFilter.ReceiveIssue(sql.Issue{ID: "3", User: "OtherBot"}); len(p) != 0 {
    44  		t.Error("OtherBot issues should be filtered")
    45  	}
    46  }
    47  
    48  // We ignore everything coming from specified people.
    49  func TestAuthorFilterIssueEvents(t *testing.T) {
    50  	ctrl := gomock.NewController(t)
    51  	defer ctrl.Finish()
    52  
    53  	plugin := NewMockPlugin(ctrl)
    54  	authorFilter := NewAuthorFilterPluginWrapper(plugin)
    55  	authorFilter.ignoredAuthors = []string{"OneBot", "OtherBot"}
    56  
    57  	expectedActor := "Person"
    58  	plugin.EXPECT().ReceiveIssueEvent(sql.IssueEvent{Actor: &expectedActor}).Return([]Point{{}})
    59  	plugin.EXPECT().ReceiveIssueEvent(sql.IssueEvent{Actor: nil}).Return([]Point{{}})
    60  
    61  	actor := "OneBot"
    62  	if p := authorFilter.ReceiveIssueEvent(sql.IssueEvent{Actor: &actor}); len(p) != 0 {
    63  		t.Error("OneBot issue-events should be filtered")
    64  	}
    65  	actor = "Person"
    66  	if p := authorFilter.ReceiveIssueEvent(sql.IssueEvent{Actor: &actor}); len(p) != 1 {
    67  		t.Error("Person issue-events shouldn't be filtered")
    68  	}
    69  	actor = "OtherBot"
    70  	if p := authorFilter.ReceiveIssueEvent(sql.IssueEvent{Actor: &actor}); len(p) != 0 {
    71  		t.Error("OtherBot issue-events should be filtered")
    72  	}
    73  	if p := authorFilter.ReceiveIssueEvent(sql.IssueEvent{Actor: nil}); len(p) != 1 {
    74  		t.Error("nil Actor issue-events shouldn't be filtered")
    75  	}
    76  }
    77  
    78  // We ignore everything coming from specified people.
    79  func TestAuthorFilterComments(t *testing.T) {
    80  	ctrl := gomock.NewController(t)
    81  	defer ctrl.Finish()
    82  
    83  	plugin := NewMockPlugin(ctrl)
    84  	authorFilter := NewAuthorFilterPluginWrapper(plugin)
    85  	authorFilter.ignoredAuthors = []string{"OneBot", "OtherBot"}
    86  
    87  	plugin.EXPECT().ReceiveComment(sql.Comment{User: "Person"}).Return([]Point{{}})
    88  
    89  	if p := authorFilter.ReceiveComment(sql.Comment{User: "OneBot"}); len(p) != 0 {
    90  		t.Error("OneBot issues should be filtered")
    91  	}
    92  	if p := authorFilter.ReceiveComment(sql.Comment{User: "Person"}); len(p) != 1 {
    93  		t.Error("Person issues shouldn't be filtered")
    94  	}
    95  	if p := authorFilter.ReceiveComment(sql.Comment{User: "OtherBot"}); len(p) != 0 {
    96  		t.Error("OtherBot issues should be filtered")
    97  	}
    98  }