-
Notifications
You must be signed in to change notification settings - Fork 128
/
sha1_test.go
73 lines (64 loc) · 1.78 KB
/
sha1_test.go
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2020 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package git
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSHA1_Equal(t *testing.T) {
tests := []struct {
s1 *SHA1
s2 interface{}
expVal bool
}{
{
s1: MustIDFromString("fcf7087e732bfe3c25328248a9bf8c3ccd85bed4"),
s2: "fcf7087e732bfe3c25328248a9bf8c3ccd85bed4",
expVal: true,
}, {
s1: MustIDFromString("fcf7087e732bfe3c25328248a9bf8c3ccd85bed4"),
s2: EmptyID,
expVal: false,
},
{
s1: MustIDFromString("fcf7087e732bfe3c25328248a9bf8c3ccd85bed4"),
s2: MustIDFromString("fcf7087e732bfe3c25328248a9bf8c3ccd85bed4").bytes,
expVal: true,
}, {
s1: MustIDFromString("fcf7087e732bfe3c25328248a9bf8c3ccd85bed4"),
s2: MustIDFromString(EmptyID).bytes,
expVal: false,
},
{
s1: MustIDFromString("fcf7087e732bfe3c25328248a9bf8c3ccd85bed4"),
s2: MustIDFromString("fcf7087e732bfe3c25328248a9bf8c3ccd85bed4"),
expVal: true,
}, {
s1: MustIDFromString("fcf7087e732bfe3c25328248a9bf8c3ccd85bed4"),
s2: MustIDFromString(EmptyID),
expVal: false,
},
{
s1: MustIDFromString("fcf7087e732bfe3c25328248a9bf8c3ccd85bed4"),
s2: []byte(EmptyID),
expVal: false,
},
}
for _, test := range tests {
t.Run("", func(t *testing.T) {
assert.Equal(t, test.expVal, test.s1.Equal(test.s2))
})
}
}
func TestNewID(t *testing.T) {
sha, err := NewID([]byte("000000"))
assert.Equal(t, errors.New("length must be 20"), err)
assert.Nil(t, sha)
}
func TestNewIDFromString(t *testing.T) {
sha, err := NewIDFromString("000000")
assert.Equal(t, errors.New("length must be 40"), err)
assert.Nil(t, sha)
}