forked from kenn-io/agentsview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhook_config_test.go
More file actions
53 lines (41 loc) · 1.17 KB
/
Copy pathhook_config_test.go
File metadata and controls
53 lines (41 loc) · 1.17 KB
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
45
46
47
48
49
50
51
52
53
package agentsview_test
import (
"os"
"testing"
"github.com/BurntSushi/toml"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type prekConfig struct {
DefaultInstallHookTypes []string `toml:"default_install_hook_types"`
Repos []prekRepo `toml:"repos"`
}
type prekRepo struct {
Hooks []prekHook `toml:"hooks"`
}
type prekHook struct {
ID string `toml:"id"`
Stages []string `toml:"stages"`
}
func TestNilAwayHookRunsOnlyOnPrePush(t *testing.T) {
contents, err := os.ReadFile("prek.toml")
require.NoError(t, err)
var config prekConfig
require.NoError(t, toml.Unmarshal(contents, &config))
assert.Contains(t, config.DefaultInstallHookTypes, "pre-commit")
assert.Contains(t, config.DefaultInstallHookTypes, "pre-push")
hook := findPrekHook(t, config, "nilaway")
assert.Equal(t, []string{"pre-push"}, hook.Stages)
}
func findPrekHook(t *testing.T, config prekConfig, id string) prekHook {
t.Helper()
for _, repo := range config.Repos {
for _, hook := range repo.Hooks {
if hook.ID == id {
return hook
}
}
}
require.Failf(t, "missing prek hook", "hook ID %q was not found", id)
return prekHook{}
}