code.gitea.io/gitea@v1.22.3/modules/git/signature_test.go (about)

     1  // Copyright 2019 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package git
     5  
     6  import (
     7  	"testing"
     8  	"time"
     9  
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func TestParseSignatureFromCommitLine(t *testing.T) {
    14  	tests := []struct {
    15  		line string
    16  		want *Signature
    17  	}{
    18  		{
    19  			line: "a b <c@d.com> 12345 +0100",
    20  			want: &Signature{
    21  				Name:  "a b",
    22  				Email: "c@d.com",
    23  				When:  time.Unix(12345, 0).In(time.FixedZone("", 3600)),
    24  			},
    25  		},
    26  		{
    27  			line: "bad line",
    28  			want: &Signature{Name: "bad line"},
    29  		},
    30  		{
    31  			line: "bad < line",
    32  			want: &Signature{Name: "bad < line"},
    33  		},
    34  		{
    35  			line: "bad > line",
    36  			want: &Signature{Name: "bad > line"},
    37  		},
    38  		{
    39  			line: "bad-line <name@example.com>",
    40  			want: &Signature{Name: "bad-line <name@example.com>"},
    41  		},
    42  	}
    43  	for _, test := range tests {
    44  		got := parseSignatureFromCommitLine(test.line)
    45  		assert.EqualValues(t, test.want, got)
    46  	}
    47  }