-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbadges_test.go
More file actions
81 lines (75 loc) · 2.14 KB
/
badges_test.go
File metadata and controls
81 lines (75 loc) · 2.14 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
package main
import (
"strings"
"testing"
)
func TestParseShieldsBadge(t *testing.T) {
tests := []struct {
name string
badgeURL string
expectedLabel string
expectedMsg string
}{
{
name: "GitHub license badge",
badgeURL: "https://img.shields.io/github/license/guttermonk/bleamd.svg?style=for-the-badge",
expectedLabel: "license",
expectedMsg: "guttermonk/bleamd",
},
{
name: "GitHub stars badge",
badgeURL: "https://img.shields.io/github/stars/guttermonk/bleamd?style=for-the-badge",
expectedLabel: "stars",
expectedMsg: "guttermonk/bleamd",
},
{
name: "Static badge",
badgeURL: "https://img.shields.io/badge/build-passing-green",
expectedLabel: "build",
expectedMsg: "passing",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
label, message, _ := parseShieldsBadge(tt.badgeURL)
if label != tt.expectedLabel {
t.Errorf("Expected label %q, got %q", tt.expectedLabel, label)
}
if message != tt.expectedMsg {
t.Errorf("Expected message %q, got %q", tt.expectedMsg, message)
}
})
}
}
func TestProcessBadges(t *testing.T) {
tests := []struct {
name string
input string
contains string
}{
{
name: "Linked GitHub license badge",
input: "[](https://github.com/guttermonk/bleamd/blob/master/LICENSE)",
contains: "[license: guttermonk/bleamd]",
},
{
name: "Linked GitHub stars badge",
input: "[](https://github.com/guttermonk/bleamd/stargazers)",
contains: "[stars: guttermonk/bleamd]",
},
{
name: "Standalone badge",
input: "",
contains: "[build: passing]",
},
}
config := DefaultConfig()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := processBadges(tt.input, config)
if !strings.Contains(result, tt.contains) {
t.Errorf("Expected output to contain %q, got %q", tt.contains, result)
}
})
}
}