Skip to content

🌱 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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 131 additions & 0 deletions hack/tools/release/notes/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,134 @@ func Test_buildSetOfPRNumbers(t *testing.T) {
})
}
}

func Test_githubFromToPRLister_listPRs(t *testing.T) {
tests := []struct {
name string
fields *githubFromToPRLister
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fields *githubFromToPRLister
lister *githubFromToPRLister

args ref
wantErr bool
}{
{
name: "Successful PR Listing",
fields: &githubFromToPRLister{
client: &githubClient{
Copy link
Member

Choose a reason for hiding this comment

The 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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using kubernetes-sigs/cluster-api ?
Probably, to use kind repository doesn't affect in the future, but to use cluster-api is more safety since the repo is itself.

},
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
l := &githubFromToPRLister{
client: tt.fields.client,
fromRef: tt.fields.fromRef,
toRef: tt.fields.toRef,
branch: tt.fields.branch,
}
_, err := l.listPRs(tt.args)
_, err := tt.lister.listPRs(tt.args)

if (err != nil) != tt.wantErr {
t.Errorf("githubFromToPRLister.listPRs() error = %v, wantErr %v", err, tt.wantErr)
return
}
})
}
}