mirror of
https://github.com/gogs/gogs.git
synced 2026-11-29 21:14:36 +01:00
64 lines
1.2 KiB
Go
64 lines
1.2 KiB
Go
package git
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestHook(t *testing.T) {
|
|
path := tempPath()
|
|
h := &Hook{
|
|
name: HookPreReceive,
|
|
path: path,
|
|
isSample: false,
|
|
content: "test content",
|
|
}
|
|
|
|
assert.Equal(t, HookPreReceive, h.Name())
|
|
assert.Equal(t, path, h.Path())
|
|
assert.False(t, h.IsSample())
|
|
assert.Equal(t, "test content", h.Content())
|
|
}
|
|
|
|
func TestHook_Update(t *testing.T) {
|
|
path := tempPath()
|
|
defer func() {
|
|
_ = os.Remove(path)
|
|
}()
|
|
|
|
h := &Hook{
|
|
name: HookPreReceive,
|
|
path: path,
|
|
isSample: false,
|
|
}
|
|
err := h.Update("test content")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
p, err := os.ReadFile(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
assert.Equal(t, "test content", string(p))
|
|
|
|
}
|
|
|
|
func TestHook_Delete(t *testing.T) {
|
|
path := tempPath()
|
|
h := &Hook{name: HookPreReceive, path: path}
|
|
require.NoError(t, h.Update("test content"))
|
|
|
|
require.NoError(t, h.Delete())
|
|
_, err := os.Stat(path)
|
|
assert.True(t, os.IsNotExist(err))
|
|
assert.True(t, h.IsSample())
|
|
assert.Equal(t, serverSideHookSamples[HookPreReceive], h.Content())
|
|
|
|
// Deleting a hook that does not exist is not an error.
|
|
require.NoError(t, h.Delete())
|
|
}
|