-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathrepo_hook_test.go
More file actions
41 lines (33 loc) · 870 Bytes
/
repo_hook_test.go
File metadata and controls
41 lines (33 loc) · 870 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
// 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 (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRepository_Hooks(t *testing.T) {
t.Run("invalid hook", func(t *testing.T) {
h, err := testrepo.Hook("", "bad_hook")
assert.Equal(t, os.ErrNotExist, err)
assert.Nil(t, h)
})
// Save "post-receive" hook with some content
postReceiveHook := testrepo.NewHook(DefaultHooksDir, HookPostReceive)
defer func() {
_ = os.Remove(postReceiveHook.Path())
}()
err := postReceiveHook.Update("echo $1 $2 $3")
if err != nil {
t.Fatal(err)
}
hooks, err := testrepo.Hooks("")
if err != nil {
t.Fatal(err)
}
assert.Equal(t, 3, len(hooks))
for i := range hooks {
assert.NotEmpty(t, hooks[i].Content())
}
}