File tree Expand file tree Collapse file tree 2 files changed +30
-24
lines changed Expand file tree Collapse file tree 2 files changed +30
-24
lines changed Original file line number Diff line number Diff line change @@ -35,21 +35,36 @@ func Test_GenerateAndSaveBadge_SaveToFile(t *testing.T) {
35
35
return
36
36
}
37
37
38
- // should save badge to file
39
- testFile := t . TempDir () + "/badge.svg"
38
+ t . Run ( "invalid file" , func ( t * testing. T ) {
39
+ t . Parallel ()
40
40
41
- buf := & bytes.Buffer {}
42
- err := GenerateAndSaveBadge (buf , Config {
43
- Badge : Badge {
44
- FileName : testFile ,
45
- },
46
- }, 100 )
47
- assert .NoError (t , err )
48
- assert .NotEmpty (t , buf .Bytes ())
41
+ err := GenerateAndSaveBadge (nil , Config {
42
+ Badge : Badge {
43
+ FileName : t .TempDir (), // should not be able to write to directory
44
+ },
45
+ }, 100 )
46
+ assert .Error (t , err )
47
+ })
49
48
50
- contentBytes , err := os .ReadFile (testFile )
51
- assert .NoError (t , err )
52
- assert .NotEmpty (t , contentBytes )
49
+ t .Run ("success" , func (t * testing.T ) {
50
+ t .Parallel ()
51
+
52
+ // should save badge to file
53
+ testFile := t .TempDir () + "/badge.svg"
54
+
55
+ buf := & bytes.Buffer {}
56
+ err := GenerateAndSaveBadge (buf , Config {
57
+ Badge : Badge {
58
+ FileName : testFile ,
59
+ },
60
+ }, 100 )
61
+ assert .NoError (t , err )
62
+ assert .Contains (t , buf .String (), "Badge saved to file" )
63
+
64
+ contentBytes , err := os .ReadFile (testFile )
65
+ assert .NoError (t , err )
66
+ assert .NotEmpty (t , contentBytes )
67
+ })
53
68
}
54
69
55
70
func Test_GenerateAndSaveBadge_SaveToCDN_NoAction (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -7,23 +7,14 @@ import (
7
7
"strings"
8
8
)
9
9
10
- //nolint:gochecknoglobals // relax
11
- var separatorToReplace = regexp .QuoteMeta (string (filepath .Separator ))
10
+ const separatorToReplace = string (filepath .Separator )
12
11
13
12
func normalizePathInRegex (path string ) string {
14
13
if runtime .GOOS != "windows" {
15
14
return path
16
15
}
17
16
18
- clean := regexp .MustCompile (`\\+/` ).
19
- ReplaceAllStringFunc (path , func (s string ) string {
20
- if strings .Count (s , "\\ " )% 2 == 0 {
21
- return s
22
- }
23
- return s [1 :]
24
- })
25
-
26
- return strings .ReplaceAll (clean , "/" , separatorToReplace )
17
+ return strings .ReplaceAll (path , "/" , separatorToReplace )
27
18
}
28
19
29
20
type regRule struct {
You can’t perform that action at this time.
0 commit comments