github.com/abayer/test-infra@v0.0.5/prow/plugins/respond_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 plugins
    18  
    19  import (
    20  	"strings"
    21  	"testing"
    22  
    23  	"k8s.io/test-infra/prow/github"
    24  )
    25  
    26  func TestFormatICResponse(t *testing.T) {
    27  	ic := github.IssueComment{
    28  		Body:    "Looks neat.\r\nI like it.\r\n",
    29  		User:    github.User{Login: "ca"},
    30  		HTMLURL: "happygoodsite.com",
    31  	}
    32  	s := "you are a nice person."
    33  	out := FormatICResponse(ic, s)
    34  	if !strings.HasPrefix(out, "@ca: you are a nice person.") {
    35  		t.Errorf("Expected compliments to the comment author, got:\n%s", out)
    36  	}
    37  	if !strings.Contains(out, ">I like it.\r\n") {
    38  		t.Errorf("Expected quotes, got:\n%s", out)
    39  	}
    40  }
    41  
    42  func TestFormatResponseRaw(t *testing.T) {
    43  
    44  	body := "Looks neat.\r\nI like it.\r\n"
    45  	user := "ca"
    46  	htmlURL := "happygoodsite.com"
    47  	comment := "you are a nice person."
    48  
    49  	out := FormatResponseRaw(body, htmlURL, user, comment)
    50  	if !strings.HasPrefix(out, "@ca: you are a nice person.") {
    51  		t.Errorf("Expected compliments to the comment author, got:\n%s", out)
    52  	}
    53  	if !strings.Contains(out, ">I like it.\r\n") {
    54  		t.Errorf("Expected quotes, got:\n%s", out)
    55  	}
    56  }