github.com/abayer/test-infra@v0.0.5/velodrome/transform/plugins/author_logger_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  	"reflect"
    21  	"testing"
    22  
    23  	"github.com/golang/mock/gomock"
    24  	"k8s.io/test-infra/velodrome/sql"
    25  )
    26  
    27  func TestAuthorLoggerEnabled(t *testing.T) {
    28  	ctrl := gomock.NewController(t)
    29  	defer ctrl.Finish()
    30  
    31  	plugin := NewMockPlugin(ctrl)
    32  	authorLogger := NewAuthorLoggerPluginWrapper(plugin)
    33  	authorLogger.enabled = true
    34  
    35  	actor := "Person"
    36  	plugin.EXPECT().ReceiveIssue(sql.Issue{User: "Person"}).Return([]Point{{}})
    37  	plugin.EXPECT().ReceiveIssueEvent(sql.IssueEvent{Actor: &actor}).Return([]Point{{}})
    38  	plugin.EXPECT().ReceiveComment(sql.Comment{User: "Person"}).Return([]Point{{}})
    39  
    40  	got := authorLogger.ReceiveIssue(sql.Issue{User: "Person"})
    41  	want := []Point{{Values: map[string]interface{}{"author": "Person"}}}
    42  	if !reflect.DeepEqual(got, want) {
    43  		t.Errorf("Failure to log author: got %+v, want %+v", got, want)
    44  	}
    45  
    46  	got = authorLogger.ReceiveIssueEvent(sql.IssueEvent{Actor: &actor})
    47  	want = []Point{{Values: map[string]interface{}{"author": "Person"}}}
    48  	if !reflect.DeepEqual(got, want) {
    49  		t.Errorf("Failure to log author: got %+v, want %+v", got, want)
    50  	}
    51  
    52  	got = authorLogger.ReceiveComment(sql.Comment{User: "Person"})
    53  	want = []Point{{Values: map[string]interface{}{"author": "Person"}}}
    54  	if !reflect.DeepEqual(got, want) {
    55  		t.Errorf("Failure to log author: got %+v, want %+v", got, want)
    56  	}
    57  }
    58  
    59  func TestAuthorLoggerDisabled(t *testing.T) {
    60  	ctrl := gomock.NewController(t)
    61  	defer ctrl.Finish()
    62  
    63  	plugin := NewMockPlugin(ctrl)
    64  	authorLogger := NewAuthorLoggerPluginWrapper(plugin)
    65  	authorLogger.enabled = false
    66  
    67  	actor := "Person"
    68  	plugin.EXPECT().ReceiveIssue(sql.Issue{User: "Person"}).Return([]Point{{}})
    69  	plugin.EXPECT().ReceiveIssueEvent(sql.IssueEvent{Actor: &actor}).Return([]Point{{}})
    70  	plugin.EXPECT().ReceiveComment(sql.Comment{User: "Person"}).Return([]Point{{}})
    71  
    72  	got := authorLogger.ReceiveIssue(sql.Issue{User: "Person"})
    73  	want := []Point{{}}
    74  	if !reflect.DeepEqual(got, want) {
    75  		t.Errorf("Failure to pass-through: got %+v, want %+v", got, want)
    76  	}
    77  
    78  	got = authorLogger.ReceiveIssueEvent(sql.IssueEvent{Actor: &actor})
    79  	want = []Point{{}}
    80  	if !reflect.DeepEqual(got, want) {
    81  		t.Errorf("Failure to pass-through: got %+v, want %+v", got, want)
    82  	}
    83  
    84  	got = authorLogger.ReceiveComment(sql.Comment{User: "Person"})
    85  	want = []Point{{}}
    86  	if !reflect.DeepEqual(got, want) {
    87  		t.Errorf("Failure to pass-through: got %+v, want %+v", got, want)
    88  	}
    89  }