github.com/abayer/test-infra@v0.0.5/mungegithub/mungers/matchers/comment/finder_test.go (about)

     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 comment
    18  
    19  import (
    20  	"reflect"
    21  	"testing"
    22  	"time"
    23  )
    24  
    25  func TestFilterComments(t *testing.T) {
    26  	comments := []*Comment{
    27  		makeCommentWithBody("1"),
    28  		makeCommentWithBody("2"),
    29  		makeCommentWithBody("3"),
    30  		makeCommentWithBody("4"),
    31  	}
    32  
    33  	emptyList := FilterComments(comments, False{})
    34  	if len(emptyList) != 0 {
    35  		t.Error("False filter shouldn't match any element")
    36  	}
    37  
    38  	fullList := FilterComments(comments, True{})
    39  	if !reflect.DeepEqual([]*Comment(fullList), comments) {
    40  		t.Error("True filter should have kept every element")
    41  	}
    42  }
    43  
    44  func makeCommentWithCreatedAt(year int, month time.Month, day int) *Comment {
    45  	date := time.Date(year, month, day, 0, 0, 0, 0, time.UTC)
    46  	return &Comment{
    47  		CreatedAt: &date,
    48  	}
    49  }
    50  
    51  func TestLastCommentDefault(t *testing.T) {
    52  	if LastComment(nil, True{}, nil) != nil {
    53  		t.Error("Empty list should return nil default")
    54  	}
    55  	if !reflect.DeepEqual(LastComment(nil, True{}, &time.Time{}), &time.Time{}) {
    56  		t.Error("Empty list should return given default value")
    57  	}
    58  }
    59  
    60  func TestLastComment(t *testing.T) {
    61  	comments := []*Comment{
    62  		makeCommentWithCreatedAt(2000, 1, 1),
    63  		makeCommentWithCreatedAt(2000, 1, 2),
    64  		makeCommentWithCreatedAt(2000, 1, 3),
    65  	}
    66  	if !reflect.DeepEqual(*LastComment(comments, True{}, nil), time.Date(2000, 1, 3, 0, 0, 0, 0, time.UTC)) {
    67  		t.Error("Should match the last comment")
    68  	}
    69  }