-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
refactor improve NoBetterThan #26126
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
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
887d6a3
improve noBetterThan
CaiCandong ffcaef6
avoid meaningless comparisons
CaiCandong cc07f3a
update swagger doc
CaiCandong f465eb8
add unit test
CaiCandong 9dd8d4d
fix lint
CaiCandong 02e39db
move commitStatusPriorities to global
CaiCandong 5adb38f
Update modules/structs/commit_status.go
CaiCandong 578141d
Update modules/structs/commit_status.go
CaiCandong 0389ed8
Merge branch 'main' into impove-NoBetterThan
GiteaBot b11baf2
Merge branch 'main' into impove-NoBetterThan
GiteaBot 659eba5
fix lint
CaiCandong ed46596
Merge branch 'impove-NoBetterThan' of github.com:CaiCandong/gitea int…
CaiCandong b06c7a7
Merge branch 'main' into impove-NoBetterThan
GiteaBot b0d9096
Merge branch 'main' into impove-NoBetterThan
GiteaBot f24e30d
Merge branch 'main' into impove-NoBetterThan
GiteaBot 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,174 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package structs | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestNoBetterThan(t *testing.T) { | ||
type args struct { | ||
css CommitStatusState | ||
css2 CommitStatusState | ||
} | ||
var unExpectedState CommitStatusState | ||
tests := []struct { | ||
name string | ||
args args | ||
want bool | ||
}{ | ||
{ | ||
name: "success is no better than success", | ||
CaiCandong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
args: args{ | ||
css: CommitStatusSuccess, | ||
css2: CommitStatusSuccess, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "success is no better than pending", | ||
args: args{ | ||
css: CommitStatusSuccess, | ||
css2: CommitStatusPending, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "success is no better than failure", | ||
args: args{ | ||
css: CommitStatusSuccess, | ||
css2: CommitStatusFailure, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "success is no better than error", | ||
args: args{ | ||
css: CommitStatusSuccess, | ||
css2: CommitStatusError, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "pending is no better than success", | ||
args: args{ | ||
css: CommitStatusPending, | ||
css2: CommitStatusSuccess, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "pending is no better than pending", | ||
args: args{ | ||
css: CommitStatusPending, | ||
css2: CommitStatusPending, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "pending is no better than failure", | ||
args: args{ | ||
css: CommitStatusPending, | ||
css2: CommitStatusFailure, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "pending is no better than error", | ||
args: args{ | ||
css: CommitStatusPending, | ||
css2: CommitStatusError, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "failure is no better than success", | ||
args: args{ | ||
css: CommitStatusFailure, | ||
css2: CommitStatusSuccess, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "failure is no better than pending", | ||
args: args{ | ||
css: CommitStatusFailure, | ||
css2: CommitStatusPending, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "failure is no better than failure", | ||
args: args{ | ||
css: CommitStatusFailure, | ||
css2: CommitStatusFailure, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "failure is no better than error", | ||
args: args{ | ||
css: CommitStatusFailure, | ||
css2: CommitStatusError, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "error is no better than success", | ||
args: args{ | ||
css: CommitStatusError, | ||
css2: CommitStatusSuccess, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "error is no better than pending", | ||
args: args{ | ||
css: CommitStatusError, | ||
css2: CommitStatusPending, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "error is no better than failure", | ||
args: args{ | ||
css: CommitStatusError, | ||
css2: CommitStatusFailure, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "error is no better than error", | ||
args: args{ | ||
css: CommitStatusError, | ||
css2: CommitStatusError, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "unExpectedState is no better than success", | ||
args: args{ | ||
css: unExpectedState, | ||
css2: CommitStatusSuccess, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "unExpectedState is no better than unExpectedState", | ||
args: args{ | ||
css: unExpectedState, | ||
css2: unExpectedState, | ||
}, | ||
want: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result := tt.args.css.NoBetterThan(tt.args.css2) | ||
if result != tt.want { | ||
t.Errorf("NoBetterThan() = %v, want %v", result, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.