Skip to content

Commit a507063

Browse files
committed
Added test cases for list.go and github.go
1 parent d23093a commit a507063

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed

hack/tools/release/notes/list_test.go

+140
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,143 @@ func Test_buildSetOfPRNumbers(t *testing.T) {
6565
})
6666
}
6767
}
68+
69+
func Test_githubFromToPRLister_listPRs(t *testing.T) {
70+
type fields struct {
71+
client *githubClient
72+
fromRef *ref
73+
toRef *ref
74+
branch string
75+
}
76+
type args struct {
77+
previousReleaseRef ref
78+
}
79+
tests := []struct {
80+
name string
81+
fields *githubFromToPRLister
82+
args ref
83+
wantErr bool
84+
}{
85+
{
86+
name: "Successful PR Listing",
87+
fields: &githubFromToPRLister{
88+
client: &githubClient{
89+
repo: "kubernetes-sigs/kind",
90+
},
91+
fromRef: ref{
92+
reType: "tags",
93+
value: "v0.26.0",
94+
},
95+
toRef: ref{
96+
reType: "tags",
97+
value: "v0.27.0",
98+
},
99+
branch: "main",
100+
},
101+
args: ref{
102+
reType: "tags",
103+
value: "v0.26.0",
104+
},
105+
wantErr: false,
106+
},
107+
{
108+
name: "Setting previousReleaseRef.value blank - should use toRef and fromRef from fields",
109+
fields: &githubFromToPRLister{
110+
client: &githubClient{
111+
repo: "kubernetes-sigs/kind",
112+
},
113+
fromRef: ref{
114+
reType: "tags",
115+
value: "v0.26.0",
116+
},
117+
toRef: ref{
118+
reType: "tags",
119+
value: "v0.27.0",
120+
},
121+
branch: "main",
122+
},
123+
args: ref{
124+
reType: "tags",
125+
value: "",
126+
},
127+
wantErr: false,
128+
},
129+
{
130+
name: "Create PR List when fromRef is not set",
131+
fields: &githubFromToPRLister{
132+
client: &githubClient{
133+
repo: "kubernetes-sigs/kind",
134+
},
135+
toRef: ref{
136+
reType: "tags",
137+
value: "v0.27.0",
138+
},
139+
branch: "main",
140+
},
141+
args: ref{
142+
reType: "tags",
143+
value: "v0.26.0",
144+
},
145+
wantErr: false,
146+
},
147+
{
148+
name: "Fail when previousReleaseRef.value is set to invalid",
149+
fields: &githubFromToPRLister{
150+
client: &githubClient{
151+
repo: "kubernetes-sigs/kind",
152+
},
153+
fromRef: ref{
154+
reType: "tags",
155+
value: "v0.26.0",
156+
},
157+
toRef: ref{
158+
reType: "tags",
159+
value: "v0.27.0",
160+
},
161+
branch: "main",
162+
},
163+
args: ref{
164+
reType: "tags",
165+
value: "invalid",
166+
},
167+
wantErr: true,
168+
},
169+
{
170+
name: "Fail when toRef and previousReleaseRef set blank",
171+
fields: &githubFromToPRLister{
172+
client: &githubClient{
173+
repo: "kubernetes-sigs/kind",
174+
},
175+
fromRef: ref{
176+
reType: "tags",
177+
value: "v0.26.0",
178+
},
179+
toRef: ref{
180+
reType: "tags",
181+
value: "",
182+
},
183+
branch: "main",
184+
},
185+
args: ref{
186+
reType: "tags",
187+
value: "",
188+
},
189+
wantErr: true,
190+
},
191+
}
192+
for _, tt := range tests {
193+
t.Run(tt.name, func(t *testing.T) {
194+
l := &githubFromToPRLister{
195+
client: tt.fields.client,
196+
fromRef: tt.fields.fromRef,
197+
toRef: tt.fields.toRef,
198+
branch: tt.fields.branch,
199+
}
200+
_, err := l.listPRs(tt.args)
201+
if (err != nil) != tt.wantErr {
202+
t.Errorf("githubFromToPRLister.listPRs() error = %v, wantErr %v", err, tt.wantErr)
203+
return
204+
}
205+
})
206+
}
207+
}

0 commit comments

Comments
 (0)