git-module

git clone git://git.lin.moe/fork/git-module.git

 1package git
 2
 3import (
 4	"os"
 5	"testing"
 6
 7	"github.com/stretchr/testify/assert"
 8)
 9
10func TestHook(t *testing.T) {
11	path := tempPath()
12	h := &Hook{
13		name:     HookPreReceive,
14		path:     path,
15		isSample: false,
16		content:  "test content",
17	}
18
19	assert.Equal(t, HookPreReceive, h.Name())
20	assert.Equal(t, path, h.Path())
21	assert.False(t, h.IsSample())
22	assert.Equal(t, "test content", h.Content())
23}
24
25func TestHook_Update(t *testing.T) {
26	path := tempPath()
27	defer func() {
28		_ = os.Remove(path)
29	}()
30
31	h := &Hook{
32		name:     HookPreReceive,
33		path:     path,
34		isSample: false,
35	}
36	err := h.Update("test content")
37	if err != nil {
38		t.Fatal(err)
39	}
40
41	p, err := os.ReadFile(path)
42	if err != nil {
43		t.Fatal(err)
44	}
45	assert.Equal(t, "test content", string(p))
46}