forked from go-git/go-git
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepository_extensions_test.go
More file actions
96 lines (85 loc) · 2.59 KB
/
repository_extensions_test.go
File metadata and controls
96 lines (85 loc) · 2.59 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package git
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/go-git/go-git/v6/config"
formatcfg "github.com/go-git/go-git/v6/plumbing/format/config"
"github.com/go-git/go-git/v6/storage/memory"
)
func TestVerifyExtensions(t *testing.T) {
t.Parallel()
tests := []struct {
name string
setup func(*testing.T, *config.Config)
wantErr string
}{
{
name: "repositoryformatversion=0: invalid extension",
setup: func(t *testing.T, cfg *config.Config) {
cfg.Core.RepositoryFormatVersion = formatcfg.Version0
cfg.Raw.Section("extensions").SetOption("unknown", "foo")
cfg.Raw.Section("extensions").SetOption("objectformat", "sha1")
},
wantErr: "repositoryformatversion does not support extension: unknown, objectformat",
},
{
name: "repositoryformatversion=0: allows supported noop",
setup: func(t *testing.T, cfg *config.Config) {
cfg.Core.RepositoryFormatVersion = formatcfg.Version0
cfg.Raw.Section("extensions").SetOption("noop", "bar")
},
},
{
name: "repositoryformatversion='': allows supported noop",
setup: func(t *testing.T, cfg *config.Config) {
cfg.Raw.Section("extensions").SetOption("noop", "bar")
},
},
{
name: "repositoryformatversion=1: rejects unknown extensions",
setup: func(t *testing.T, cfg *config.Config) {
cfg.Core.RepositoryFormatVersion = formatcfg.Version1
cfg.Raw.Section("extensions").SetOption("unknownext", "true")
},
wantErr: "unknown extension: unknownext",
},
{
name: "repositoryformatversion=1: allows known extension",
setup: func(t *testing.T, cfg *config.Config) {
cfg.Core.RepositoryFormatVersion = formatcfg.Version1
cfg.Raw.Section("extensions").SetOption("NOOP", "foo")
cfg.Raw.Section("extensions").SetOption("noop-v1", "bar")
},
},
{
name: "repositoryformatversion=1: allows objectformat=sha1",
setup: func(t *testing.T, cfg *config.Config) {
cfg.Core.RepositoryFormatVersion = formatcfg.Version1
cfg.Raw.Section("extensions").SetOption("objectformat", "sha1")
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
st := memory.NewStorage()
r, err := Init(st)
require.NoError(t, err)
require.NotNil(t, r)
cfg, err := st.Config()
require.NoError(t, err)
tt.setup(t, cfg)
require.NoError(t, st.SetConfig(cfg))
r, err = Open(st, nil)
if tt.wantErr != "" {
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
assert.Nil(t, r)
} else {
require.NoError(t, err)
assert.NotNil(t, r)
}
})
}
}