|
| 1 | +// Copyright 2023 The Gitea Authors. All rights reserved. |
| 2 | +// SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +package structs |
| 5 | + |
| 6 | +import ( |
| 7 | + "testing" |
| 8 | +) |
| 9 | + |
| 10 | +func TestNoBetterThan(t *testing.T) { |
| 11 | + type args struct { |
| 12 | + css CommitStatusState |
| 13 | + css2 CommitStatusState |
| 14 | + } |
| 15 | + var unExpectedState CommitStatusState |
| 16 | + tests := []struct { |
| 17 | + name string |
| 18 | + args args |
| 19 | + want bool |
| 20 | + }{ |
| 21 | + { |
| 22 | + name: "success is no better than success", |
| 23 | + args: args{ |
| 24 | + css: CommitStatusSuccess, |
| 25 | + css2: CommitStatusSuccess, |
| 26 | + }, |
| 27 | + want: true, |
| 28 | + }, |
| 29 | + { |
| 30 | + name: "success is no better than pending", |
| 31 | + args: args{ |
| 32 | + css: CommitStatusSuccess, |
| 33 | + css2: CommitStatusPending, |
| 34 | + }, |
| 35 | + want: false, |
| 36 | + }, |
| 37 | + { |
| 38 | + name: "success is no better than failure", |
| 39 | + args: args{ |
| 40 | + css: CommitStatusSuccess, |
| 41 | + css2: CommitStatusFailure, |
| 42 | + }, |
| 43 | + want: false, |
| 44 | + }, |
| 45 | + { |
| 46 | + name: "success is no better than error", |
| 47 | + args: args{ |
| 48 | + css: CommitStatusSuccess, |
| 49 | + css2: CommitStatusError, |
| 50 | + }, |
| 51 | + want: false, |
| 52 | + }, |
| 53 | + { |
| 54 | + name: "pending is no better than success", |
| 55 | + args: args{ |
| 56 | + css: CommitStatusPending, |
| 57 | + css2: CommitStatusSuccess, |
| 58 | + }, |
| 59 | + want: true, |
| 60 | + }, |
| 61 | + { |
| 62 | + name: "pending is no better than pending", |
| 63 | + args: args{ |
| 64 | + css: CommitStatusPending, |
| 65 | + css2: CommitStatusPending, |
| 66 | + }, |
| 67 | + want: true, |
| 68 | + }, |
| 69 | + { |
| 70 | + name: "pending is no better than failure", |
| 71 | + args: args{ |
| 72 | + css: CommitStatusPending, |
| 73 | + css2: CommitStatusFailure, |
| 74 | + }, |
| 75 | + want: false, |
| 76 | + }, |
| 77 | + { |
| 78 | + name: "pending is no better than error", |
| 79 | + args: args{ |
| 80 | + css: CommitStatusPending, |
| 81 | + css2: CommitStatusError, |
| 82 | + }, |
| 83 | + want: false, |
| 84 | + }, |
| 85 | + { |
| 86 | + name: "failure is no better than success", |
| 87 | + args: args{ |
| 88 | + css: CommitStatusFailure, |
| 89 | + css2: CommitStatusSuccess, |
| 90 | + }, |
| 91 | + want: true, |
| 92 | + }, |
| 93 | + { |
| 94 | + name: "failure is no better than pending", |
| 95 | + args: args{ |
| 96 | + css: CommitStatusFailure, |
| 97 | + css2: CommitStatusPending, |
| 98 | + }, |
| 99 | + want: true, |
| 100 | + }, |
| 101 | + { |
| 102 | + name: "failure is no better than failure", |
| 103 | + args: args{ |
| 104 | + css: CommitStatusFailure, |
| 105 | + css2: CommitStatusFailure, |
| 106 | + }, |
| 107 | + want: true, |
| 108 | + }, |
| 109 | + { |
| 110 | + name: "failure is no better than error", |
| 111 | + args: args{ |
| 112 | + css: CommitStatusFailure, |
| 113 | + css2: CommitStatusError, |
| 114 | + }, |
| 115 | + want: false, |
| 116 | + }, |
| 117 | + { |
| 118 | + name: "error is no better than success", |
| 119 | + args: args{ |
| 120 | + css: CommitStatusError, |
| 121 | + css2: CommitStatusSuccess, |
| 122 | + }, |
| 123 | + want: true, |
| 124 | + }, |
| 125 | + { |
| 126 | + name: "error is no better than pending", |
| 127 | + args: args{ |
| 128 | + css: CommitStatusError, |
| 129 | + css2: CommitStatusPending, |
| 130 | + }, |
| 131 | + want: true, |
| 132 | + }, |
| 133 | + { |
| 134 | + name: "error is no better than failure", |
| 135 | + args: args{ |
| 136 | + css: CommitStatusError, |
| 137 | + css2: CommitStatusFailure, |
| 138 | + }, |
| 139 | + want: true, |
| 140 | + }, |
| 141 | + { |
| 142 | + name: "error is no better than error", |
| 143 | + args: args{ |
| 144 | + css: CommitStatusError, |
| 145 | + css2: CommitStatusError, |
| 146 | + }, |
| 147 | + want: true, |
| 148 | + }, |
| 149 | + { |
| 150 | + name: "unExpectedState is no better than success", |
| 151 | + args: args{ |
| 152 | + css: unExpectedState, |
| 153 | + css2: CommitStatusSuccess, |
| 154 | + }, |
| 155 | + want: false, |
| 156 | + }, |
| 157 | + { |
| 158 | + name: "unExpectedState is no better than unExpectedState", |
| 159 | + args: args{ |
| 160 | + css: unExpectedState, |
| 161 | + css2: unExpectedState, |
| 162 | + }, |
| 163 | + want: false, |
| 164 | + }, |
| 165 | + } |
| 166 | + for _, tt := range tests { |
| 167 | + t.Run(tt.name, func(t *testing.T) { |
| 168 | + result := tt.args.css.NoBetterThan(tt.args.css2) |
| 169 | + if result != tt.want { |
| 170 | + t.Errorf("NoBetterThan() = %v, want %v", result, tt.want) |
| 171 | + } |
| 172 | + }) |
| 173 | + } |
| 174 | +} |
0 commit comments