...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package statuscheck
17
18 import (
19 "testing"
20
21 "github.com/chaos-mesh/chaos-mesh/api/v1alpha1"
22 )
23
24 func Test_isThresholdExceed(t *testing.T) {
25 type args struct {
26 records []v1alpha1.StatusCheckRecord
27 outcome v1alpha1.StatusCheckOutcome
28 threshold int
29 }
30 tests := []struct {
31 name string
32 args args
33 want bool
34 }{
35 {
36 name: "not exceed",
37 args: args{
38 records: []v1alpha1.StatusCheckRecord{
39 {Outcome: v1alpha1.StatusCheckOutcomeFailure},
40 {Outcome: v1alpha1.StatusCheckOutcomeSuccess},
41 {Outcome: v1alpha1.StatusCheckOutcomeFailure},
42 },
43 outcome: v1alpha1.StatusCheckOutcomeFailure,
44 threshold: 2,
45 },
46 want: false,
47 },
48 {
49 name: "exceed",
50 args: args{
51 records: []v1alpha1.StatusCheckRecord{
52 {Outcome: v1alpha1.StatusCheckOutcomeFailure},
53 },
54 outcome: v1alpha1.StatusCheckOutcomeFailure,
55 threshold: 1,
56 },
57 want: true,
58 },
59 {
60 name: "exceed",
61 args: args{
62 records: []v1alpha1.StatusCheckRecord{
63 {Outcome: v1alpha1.StatusCheckOutcomeSuccess},
64 {Outcome: v1alpha1.StatusCheckOutcomeFailure},
65 {Outcome: v1alpha1.StatusCheckOutcomeFailure},
66 },
67 outcome: v1alpha1.StatusCheckOutcomeFailure,
68 threshold: 2,
69 },
70 want: true,
71 },
72 {
73 name: "threshold is bigger than the length of record",
74 args: args{
75 records: []v1alpha1.StatusCheckRecord{
76 {Outcome: v1alpha1.StatusCheckOutcomeFailure},
77 {Outcome: v1alpha1.StatusCheckOutcomeFailure},
78 },
79 outcome: v1alpha1.StatusCheckOutcomeFailure,
80 threshold: 3,
81 },
82 want: false,
83 },
84 }
85 for _, tt := range tests {
86 t.Run(tt.name, func(t *testing.T) {
87 if got := isThresholdExceed(tt.args.records, tt.args.outcome, tt.args.threshold); got != tt.want {
88 t.Errorf("isThresholdExceed() = %v, want %v", got, tt.want)
89 }
90 })
91 }
92 }
93