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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
package gittest
import (
"testing"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper"
)
func TestCountingCommandFactory(t *testing.T) {
cfg, repo, _ := setup(t)
ctx := testhelper.Context(t)
for _, tc := range []struct {
desc string
run func(t *testing.T, f *CountingCommandFactory)
expected map[string]uint64
}{
{
desc: "counts a command",
run: func(t *testing.T, f *CountingCommandFactory) {
_, err := f.New(ctx, repo, git.Command{Name: "cat-file"})
require.NoError(t, err)
},
expected: map[string]uint64{"cat-file": 1},
},
{
desc: "counts multiple commands",
run: func(t *testing.T, f *CountingCommandFactory) {
_, err := f.New(ctx, repo, git.Command{Name: "cat-file"})
require.NoError(t, err)
_, err = f.New(ctx, repo, git.Command{Name: "cat-file"})
require.NoError(t, err)
_, err = f.New(ctx, repo, git.Command{Name: "ls-tree"})
require.NoError(t, err)
},
expected: map[string]uint64{
"cat-file": 2,
"ls-tree": 1,
},
},
{
desc: "counts get reset",
run: func(t *testing.T, f *CountingCommandFactory) {
_, err := f.New(ctx, repo, git.Command{Name: "cat-file"})
require.NoError(t, err)
_, err = f.New(ctx, repo, git.Command{Name: "ls-tree"})
require.NoError(t, err)
f.ResetCount()
_, err = f.New(ctx, repo, git.Command{Name: "cat-file"})
require.NoError(t, err)
},
expected: map[string]uint64{"cat-file": 1},
},
} {
t.Run(tc.desc, func(t *testing.T) {
f := NewCountingCommandFactory(t, cfg)
tc.run(t, f)
for k, v := range tc.expected {
require.Equal(t, v, f.CommandCount(k))
}
})
}
}
|