File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ package gitutil
2
+
3
+ import (
4
+ "fmt"
5
+ "testing"
6
+
7
+ "github.com/stretchr/testify/assert"
8
+ )
9
+
10
+ func TestIsCommitSHA (t * testing.T ) {
11
+ for truthy , commits := range map [bool ][]string {
12
+ true : {
13
+ "01234567890abcdef01234567890abcdef012345" , // 40 valid characters (SHA-1)
14
+ },
15
+ false : {
16
+ "" , // empty string
17
+ "abcdef" , // too short
18
+
19
+ "123456789012345678901234567890123456789" , // 39 valid characters
20
+ "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" , // 40 invalid characters
21
+ "12345678901234567890123456789012345678901" , // 41 valid characters
22
+
23
+ "01234567890abcdef01234567890abcdef01234567890abcdef01234567890a" , // 63 valid characters
24
+ "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" , // 64 invalid characters
25
+ "01234567890abcdef01234567890abcdef01234567890abcdef01234567890abc" , // 65 valid characters
26
+
27
+ // TODO: add SHA-256 support and move this up to the "true" section
28
+ "01234567890abcdef01234567890abcdef01234567890abcdef01234567890ab" , // 64 valid characters (SHA-256)
29
+ },
30
+ } {
31
+ for _ , commit := range commits {
32
+ t .Run (fmt .Sprintf ("%t/%q" , truthy , commit ), func (t * testing.T ) {
33
+ assert .Equal (t , truthy , IsCommitSHA (commit ))
34
+ })
35
+ }
36
+ }
37
+ }
You can’t perform that action at this time.
0 commit comments