-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathfile_test.go
More file actions
99 lines (88 loc) · 1.99 KB
/
file_test.go
File metadata and controls
99 lines (88 loc) · 1.99 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
97
98
99
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package check
import (
"io/fs"
"path/filepath"
"testing"
"testing/fstest"
)
func TestFileSizeCheck(t *testing.T) {
t.Parallel()
testCases := map[string]struct {
FileSystem fs.FS
Size int64
ExpectError bool
}{
"under limit": {
FileSystem: fstest.MapFS{
"file.md": {
Data: make([]byte, RegistryMaximumSizeOfFile-1),
},
},
},
"on limit": {
FileSystem: fstest.MapFS{
"file.md": {
Data: make([]byte, RegistryMaximumSizeOfFile),
},
},
ExpectError: true,
},
"over limit": {
FileSystem: fstest.MapFS{
"file.md": {
Data: make([]byte, RegistryMaximumSizeOfFile+1),
},
},
ExpectError: true,
},
}
for name, testCase := range testCases {
name := name
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()
got := FileSizeCheck(testCase.FileSystem, "file.md")
if got == nil && testCase.ExpectError {
t.Errorf("expected error, got no error")
}
if got != nil && !testCase.ExpectError {
t.Errorf("expected no error, got error: %s", got)
}
})
}
}
func TestFullPath(t *testing.T) {
t.Parallel()
testCases := map[string]struct {
FileOptions *FileOptions
Path string
Expect string
}{
"without base path": {
FileOptions: &FileOptions{},
Path: filepath.FromSlash("docs/resources/thing.md"),
Expect: filepath.FromSlash("docs/resources/thing.md"),
},
"with base path": {
FileOptions: &FileOptions{
BasePath: filepath.FromSlash("/full/path/to"),
},
Path: filepath.FromSlash("docs/resources/thing.md"),
Expect: filepath.FromSlash("/full/path/to/docs/resources/thing.md"),
},
}
for name, testCase := range testCases {
name := name
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()
got := testCase.FileOptions.FullPath(testCase.Path)
want := testCase.Expect
if got != want {
t.Errorf("expected %s, got %s", want, got)
}
})
}
}