-
Notifications
You must be signed in to change notification settings - Fork 1.4k
🌱 Added test cases for list.go and github.go #11937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -65,3 +65,134 @@ func Test_buildSetOfPRNumbers(t *testing.T) { | |||||||||||||||||
}) | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
func Test_githubFromToPRLister_listPRs(t *testing.T) { | ||||||||||||||||||
tests := []struct { | ||||||||||||||||||
name string | ||||||||||||||||||
fields *githubFromToPRLister | ||||||||||||||||||
args ref | ||||||||||||||||||
wantErr bool | ||||||||||||||||||
}{ | ||||||||||||||||||
{ | ||||||||||||||||||
name: "Successful PR Listing", | ||||||||||||||||||
fields: &githubFromToPRLister{ | ||||||||||||||||||
client: &githubClient{ | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering if we should better use some mock client instead of reaching out to github on unit tests (rate-limiting could apply and make the test flaky) |
||||||||||||||||||
repo: "kubernetes-sigs/kind", | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about using kubernetes-sigs/cluster-api ? |
||||||||||||||||||
}, | ||||||||||||||||||
fromRef: ref{ | ||||||||||||||||||
reType: "tags", | ||||||||||||||||||
value: "v0.26.0", | ||||||||||||||||||
}, | ||||||||||||||||||
toRef: ref{ | ||||||||||||||||||
reType: "tags", | ||||||||||||||||||
value: "v0.27.0", | ||||||||||||||||||
}, | ||||||||||||||||||
branch: "main", | ||||||||||||||||||
}, | ||||||||||||||||||
args: ref{ | ||||||||||||||||||
reType: "tags", | ||||||||||||||||||
value: "v0.26.0", | ||||||||||||||||||
}, | ||||||||||||||||||
wantErr: false, | ||||||||||||||||||
}, | ||||||||||||||||||
{ | ||||||||||||||||||
name: "Setting previousReleaseRef.value blank - should use toRef and fromRef from fields", | ||||||||||||||||||
fields: &githubFromToPRLister{ | ||||||||||||||||||
client: &githubClient{ | ||||||||||||||||||
repo: "kubernetes-sigs/kind", | ||||||||||||||||||
}, | ||||||||||||||||||
fromRef: ref{ | ||||||||||||||||||
reType: "tags", | ||||||||||||||||||
value: "v0.26.0", | ||||||||||||||||||
}, | ||||||||||||||||||
toRef: ref{ | ||||||||||||||||||
reType: "tags", | ||||||||||||||||||
value: "v0.27.0", | ||||||||||||||||||
}, | ||||||||||||||||||
branch: "main", | ||||||||||||||||||
}, | ||||||||||||||||||
args: ref{ | ||||||||||||||||||
reType: "tags", | ||||||||||||||||||
value: "", | ||||||||||||||||||
}, | ||||||||||||||||||
wantErr: false, | ||||||||||||||||||
}, | ||||||||||||||||||
{ | ||||||||||||||||||
name: "Create PR List when fromRef is not set", | ||||||||||||||||||
fields: &githubFromToPRLister{ | ||||||||||||||||||
client: &githubClient{ | ||||||||||||||||||
repo: "kubernetes-sigs/kind", | ||||||||||||||||||
}, | ||||||||||||||||||
toRef: ref{ | ||||||||||||||||||
reType: "tags", | ||||||||||||||||||
value: "v0.27.0", | ||||||||||||||||||
}, | ||||||||||||||||||
branch: "main", | ||||||||||||||||||
}, | ||||||||||||||||||
args: ref{ | ||||||||||||||||||
reType: "tags", | ||||||||||||||||||
value: "v0.26.0", | ||||||||||||||||||
}, | ||||||||||||||||||
wantErr: false, | ||||||||||||||||||
}, | ||||||||||||||||||
{ | ||||||||||||||||||
name: "Fail when previousReleaseRef.value is set to invalid", | ||||||||||||||||||
fields: &githubFromToPRLister{ | ||||||||||||||||||
client: &githubClient{ | ||||||||||||||||||
repo: "kubernetes-sigs/kind", | ||||||||||||||||||
}, | ||||||||||||||||||
fromRef: ref{ | ||||||||||||||||||
reType: "tags", | ||||||||||||||||||
value: "v0.26.0", | ||||||||||||||||||
}, | ||||||||||||||||||
toRef: ref{ | ||||||||||||||||||
reType: "tags", | ||||||||||||||||||
value: "v0.27.0", | ||||||||||||||||||
}, | ||||||||||||||||||
branch: "main", | ||||||||||||||||||
}, | ||||||||||||||||||
args: ref{ | ||||||||||||||||||
reType: "tags", | ||||||||||||||||||
value: "invalid", | ||||||||||||||||||
}, | ||||||||||||||||||
wantErr: true, | ||||||||||||||||||
}, | ||||||||||||||||||
{ | ||||||||||||||||||
name: "Fail when toRef and previousReleaseRef set blank", | ||||||||||||||||||
fields: &githubFromToPRLister{ | ||||||||||||||||||
client: &githubClient{ | ||||||||||||||||||
repo: "kubernetes-sigs/kind", | ||||||||||||||||||
}, | ||||||||||||||||||
fromRef: ref{ | ||||||||||||||||||
reType: "tags", | ||||||||||||||||||
value: "v0.26.0", | ||||||||||||||||||
}, | ||||||||||||||||||
toRef: ref{ | ||||||||||||||||||
reType: "tags", | ||||||||||||||||||
value: "", | ||||||||||||||||||
}, | ||||||||||||||||||
branch: "main", | ||||||||||||||||||
}, | ||||||||||||||||||
args: ref{ | ||||||||||||||||||
reType: "tags", | ||||||||||||||||||
value: "", | ||||||||||||||||||
}, | ||||||||||||||||||
wantErr: true, | ||||||||||||||||||
}, | ||||||||||||||||||
} | ||||||||||||||||||
for _, tt := range tests { | ||||||||||||||||||
t.Run(tt.name, func(t *testing.T) { | ||||||||||||||||||
l := &githubFromToPRLister{ | ||||||||||||||||||
client: tt.fields.client, | ||||||||||||||||||
fromRef: tt.fields.fromRef, | ||||||||||||||||||
toRef: tt.fields.toRef, | ||||||||||||||||||
branch: tt.fields.branch, | ||||||||||||||||||
} | ||||||||||||||||||
_, err := l.listPRs(tt.args) | ||||||||||||||||||
Comment on lines
+185
to
+191
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
if (err != nil) != tt.wantErr { | ||||||||||||||||||
t.Errorf("githubFromToPRLister.listPRs() error = %v, wantErr %v", err, tt.wantErr) | ||||||||||||||||||
return | ||||||||||||||||||
} | ||||||||||||||||||
}) | ||||||||||||||||||
} | ||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.