-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest_test.go
More file actions
44 lines (38 loc) · 962 Bytes
/
request_test.go
File metadata and controls
44 lines (38 loc) · 962 Bytes
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
package main
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestValidateRevisionArgAllowsCommonGitRevisions(t *testing.T) {
t.Parallel()
for _, revision := range []string{
"HEAD",
"HEAD~3",
"origin/main",
"refs/heads/main",
"v1.2.3",
"abc1234",
"0123456789abcdef0123456789abcdef01234567",
} {
require.NoError(t, validateRevisionArg("revision", revision), revision)
}
}
func TestValidateRevisionArgRejectsUnsafeValues(t *testing.T) {
t.Parallel()
tests := []struct {
revision string
want string
}{
{revision: "", want: "is required"},
{revision: "-bad", want: "must not start with '-'"},
{revision: "head:bad", want: "must not contain ':'"},
{revision: "head\x00bad", want: "must not contain NUL bytes"},
}
for _, tt := range tests {
t.Run(tt.want, func(t *testing.T) {
t.Parallel()
err := validateRevisionArg("--head-sha", tt.revision)
require.ErrorContains(t, err, tt.want)
})
}
}