summaryrefslogtreecommitdiffstats
path: root/modules/git/signature_test.go
blob: 92681feea9f68e14f00aa635e2b01738d4e1627b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2019 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package git

import (
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
)

func TestParseSignatureFromCommitLine(t *testing.T) {
	tests := []struct {
		line string
		want *Signature
	}{
		{
			line: "a b <c@d.com> 12345 +0100",
			want: &Signature{
				Name:  "a b",
				Email: "c@d.com",
				When:  time.Unix(12345, 0).In(time.FixedZone("", 3600)),
			},
		},
		{
			line: "bad line",
			want: &Signature{Name: "bad line"},
		},
		{
			line: "bad < line",
			want: &Signature{Name: "bad < line"},
		},
		{
			line: "bad > line",
			want: &Signature{Name: "bad > line"},
		},
		{
			line: "bad-line <name@example.com>",
			want: &Signature{Name: "bad-line <name@example.com>"},
		},
	}
	for _, test := range tests {
		got := parseSignatureFromCommitLine(test.line)
		assert.EqualValues(t, test.want, got)
	}
}