mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-11 19:09:34 +02:00
improvements
This commit is contained in:
4 files changed
+7
-211
No files matched your search
@@ -20,33 +20,10 @@ const (
|
||||
CommitStatusWarning CommitStatusState = "warning"
|
||||
)
|
||||
|
||||
var commitStatusPriorities = map[CommitStatusState]int{
|
||||
CommitStatusError: 0,
|
||||
CommitStatusFailure: 1,
|
||||
CommitStatusWarning: 2,
|
||||
CommitStatusPending: 3,
|
||||
CommitStatusSuccess: 4,
|
||||
}
|
||||
|
||||
func (css CommitStatusState) String() string {
|
||||
return string(css)
|
||||
}
|
||||
|
||||
// NoBetterThan returns true if this State is no better than the given State
|
||||
// This function only handles the states defined in CommitStatusPriorities
|
||||
func (css CommitStatusState) NoBetterThan(css2 CommitStatusState) bool {
|
||||
// NoBetterThan only handles the 5 states above
|
||||
if _, exist := commitStatusPriorities[css]; !exist {
|
||||
return false
|
||||
}
|
||||
|
||||
if _, exist := commitStatusPriorities[css2]; !exist {
|
||||
return false
|
||||
}
|
||||
|
||||
return commitStatusPriorities[css] <= commitStatusPriorities[css2]
|
||||
}
|
||||
|
||||
// IsPending represents if commit status state is pending
|
||||
func (css CommitStatusState) IsPending() bool {
|
||||
return css == CommitStatusPending
|
||||
|
||||
@@ -1,174 +0,0 @@
|
||||
// Copyright 2023 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package commitstatus
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
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",
|
||||
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)
|
||||
assert.Equal(t, tt.want, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user