-
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
Merged
k8s-ci-robot
merged 6 commits into
kubernetes-sigs:main
from
irapandey:test_case_release_note_list_github
Oct 13, 2025
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
525afcc
Added test cases for list.go and github.go
irapandey 25ff8d8
Linting issues fixed
irapandey a74a438
mock github and fix test cases
irapandey 262bdc1
fixing broken test
irapandey 4b4459f
PR Review changes
irapandey de9972c
PR review changes
irapandey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| //go:build tools | ||
| // +build tools | ||
|
|
||
| /* | ||
| Copyright 2025 The Kubernetes Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "time" | ||
| ) | ||
|
|
||
| // mockGithubClient is a mock implementation of githubClientInterface for testing. | ||
| type mockGithubClient struct { | ||
| // Mock responses | ||
| diffResponse *githubDiff | ||
| refResponse githubRef | ||
| tagResponse githubTag | ||
| commitResponse githubCommit | ||
| prsResponse []githubPR | ||
|
|
||
| // Mock errors | ||
| diffError error | ||
| refError error | ||
| tagError error | ||
| commitError error | ||
| prsError error | ||
| } | ||
|
|
||
| // Ensure mockGithubClient implements githubClientInterface. | ||
| var _ githubClientInterface = (*mockGithubClient)(nil) | ||
|
|
||
| func (m *mockGithubClient) getDiffAllCommits(_, _ string) (*githubDiff, error) { | ||
| if m.diffError != nil { | ||
| return nil, m.diffError | ||
| } | ||
| return m.diffResponse, nil | ||
| } | ||
|
|
||
| func (m *mockGithubClient) getRef(_ string) (githubRef, error) { | ||
| if m.refError != nil { | ||
| return githubRef{}, m.refError | ||
| } | ||
| return m.refResponse, nil | ||
| } | ||
|
|
||
| func (m *mockGithubClient) getTag(_ string) (githubTag, error) { | ||
| if m.tagError != nil { | ||
| return githubTag{}, m.tagError | ||
| } | ||
| return m.tagResponse, nil | ||
| } | ||
|
|
||
| func (m *mockGithubClient) getCommit(_ string) (githubCommit, error) { | ||
| if m.commitError != nil { | ||
| return githubCommit{}, m.commitError | ||
| } | ||
| return m.commitResponse, nil | ||
| } | ||
|
|
||
| func (m *mockGithubClient) listMergedPRs(_, _ time.Time, _ ...string) ([]githubPR, error) { | ||
| if m.prsError != nil { | ||
| return nil, m.prsError | ||
| } | ||
| return m.prsResponse, nil | ||
| } | ||
|
|
||
| // newMockGithubClient creates a new mock client with default responses. | ||
| func newMockGithubClient() *mockGithubClient { | ||
| return &mockGithubClient{ | ||
| diffResponse: &githubDiff{ | ||
| MergeBaseCommit: githubCommitNode{ | ||
| Commit: githubCommit{ | ||
| Message: "Merge commit", | ||
| Committer: githubCommitter{ | ||
| Date: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC), | ||
| }, | ||
| }, | ||
| }, | ||
| Commits: []githubCommitNode{ | ||
| { | ||
| Commit: githubCommit{ | ||
| Message: "Merge pull request #1234 from test/branch", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| refResponse: githubRef{ | ||
| Object: githubObject{ | ||
| ObjectType: commitType, | ||
| SHA: "abc123", | ||
| }, | ||
| }, | ||
| tagResponse: githubTag{ | ||
| Object: githubObject{ | ||
| ObjectType: tagType, | ||
| SHA: "def456", | ||
| }, | ||
| }, | ||
| commitResponse: githubCommit{ | ||
| Message: "Test commit", | ||
| Committer: githubCommitter{ | ||
| Date: time.Date(2023, 1, 2, 0, 0, 0, 0, time.UTC), | ||
| }, | ||
| }, | ||
| prsResponse: []githubPR{ | ||
| { | ||
| Number: 1234, | ||
| Title: "Test PR", | ||
| Labels: []githubLabel{ | ||
| {Name: "area/testing"}, | ||
| }, | ||
| User: githubUser{ | ||
| Login: "testuser", | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| // newMockGithubClientWithError creates a mock client that returns an error for specific operations. | ||
| func newMockGithubClientWithError(operation string, err error) *mockGithubClient { | ||
| mock := newMockGithubClient() | ||
| switch operation { | ||
| case "diff": | ||
| mock.diffError = err | ||
| case "ref": | ||
| mock.refError = err | ||
| case "tag": | ||
| mock.tagError = err | ||
| case "commit": | ||
| mock.commitError = err | ||
| case "prs": | ||
| mock.prsError = err | ||
| } | ||
| return mock | ||
| } | ||
|
|
||
| // newMockGithubClientForInvalidRef creates a mock client that simulates invalid ref scenarios. | ||
| func newMockGithubClientForInvalidRef() *mockGithubClient { | ||
| mock := newMockGithubClient() | ||
| mock.diffError = fmt.Errorf("invalid ref") | ||
| return mock | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.