-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_client_test.go
More file actions
188 lines (167 loc) · 4.27 KB
/
github_client_test.go
File metadata and controls
188 lines (167 loc) · 4.27 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package main
import (
"strings"
"testing"
)
func TestResolveVanityImport(t *testing.T) {
tests := []struct {
input string
expected string
}{
{
input: "k8s.io/api",
expected: "github.com/kubernetes/api",
},
{
input: "k8s.io/client-go",
expected: "github.com/kubernetes/client-go",
},
{
input: "sigs.k8s.io/yaml",
expected: "github.com/kubernetes-sigs/yaml",
},
{
input: "go.uber.org/zap",
expected: "github.com/uber-go/zap",
},
{
input: "golang.org/x/tools",
expected: "github.com/golang/tools",
},
{
input: "google.golang.org/grpc",
expected: "github.com/grpc/grpc-go",
},
{
input: "google.golang.org/protobuf",
expected: "github.com/protocolbuffers/protobuf-go",
},
{
input: "gocloud.dev/blob",
expected: "github.com/google/go-cloud/blob",
},
{
input: "github.com/foo/bar",
expected: "github.com/foo/bar",
},
{
input: "example.com/unknown",
expected: "example.com/unknown",
},
}
for _, tt := range tests {
result := resolveVanityImport(tt.input)
if result != tt.expected {
t.Errorf("resolveVanityImport(%q) = %q, want %q", tt.input, result, tt.expected)
}
}
}
func TestExtractGitHubOwnerRepo(t *testing.T) {
tests := []struct {
input string
expectOwner string
expectRepo string
expectOk bool
}{
{
input: "github.com/google/go-github",
expectOwner: "google",
expectRepo: "go-github",
expectOk: true,
},
{
input: "github.com/kubernetes/kubernetes",
expectOwner: "kubernetes",
expectRepo: "kubernetes",
expectOk: true,
},
{
input: "k8s.io/api",
expectOk: false,
},
{
input: "github.com/foo",
expectOk: false,
},
{
input: "example.com/foo/bar",
expectOk: false,
},
}
for _, tt := range tests {
owner, repo, ok := extractGitHubOwnerRepo(tt.input)
if ok != tt.expectOk {
t.Errorf("extractGitHubOwnerRepo(%q) ok = %v, want %v", tt.input, ok, tt.expectOk)
continue
}
if ok {
if owner != tt.expectOwner {
t.Errorf("extractGitHubOwnerRepo(%q) owner = %q, want %q", tt.input, owner, tt.expectOwner)
}
if repo != tt.expectRepo {
t.Errorf("extractGitHubOwnerRepo(%q) repo = %q, want %q", tt.input, repo, tt.expectRepo)
}
}
}
}
func TestExtractBreakingChanges(t *testing.T) {
content := `
# v3.0.0
## ⚠️ Breaking Changes
BREAKING: Removed deprecated API endpoint /v1/users
⚠️ Changed function signature for ProcessData(ctx context.Context)
This is not a breaking change
## ⚠️ Changes
REMOVED: Old feature that was deprecated in v2.5.0
[breaking] Important API change: Authentication now requires tokens
## Features
Added new feature
`
changes := extractBreakingChanges(content)
if len(changes) == 0 {
t.Fatal("Expected to find breaking changes, got none")
}
// Should find at least 3 breaking changes (but skip generic headers)
if len(changes) < 3 {
t.Errorf("Expected at least 3 breaking changes, got %d: %v", len(changes), changes)
}
// Should limit to 5 changes max
if len(changes) > 5 {
t.Errorf("Expected max 5 breaking changes, got %d", len(changes))
}
// Verify it DOESN'T capture generic headers
for _, change := range changes {
changeLower := strings.ToLower(change)
if changeLower == "changes" || changeLower == "breaking changes" || changeLower == "breaking" {
t.Errorf("Should not capture generic header: %q", change)
}
// Should have substantial content (min 10 chars)
if len(change) < 10 {
t.Errorf("Change too short (likely a header): %q", change)
}
}
// Verify it captures actual breaking changes
hasAPIRemoval := false
hasFunctionChange := false
hasFeatureRemoval := false
for _, change := range changes {
if strings.Contains(change, "Removed deprecated API endpoint") {
hasAPIRemoval = true
}
if strings.Contains(change, "Changed function signature") {
hasFunctionChange = true
}
if strings.Contains(change, "Old feature that was deprecated") {
hasFeatureRemoval = true
}
}
if !hasAPIRemoval {
t.Errorf("Expected to find API removal in changes: %v", changes)
}
if !hasFunctionChange {
t.Errorf("Expected to find function change in changes: %v", changes)
}
if !hasFeatureRemoval {
t.Errorf("Expected to find feature removal in changes: %v", changes)
}
}