File tree 1 file changed +82
-0
lines changed
1 file changed +82
-0
lines changed Original file line number Diff line number Diff line change @@ -2290,3 +2290,85 @@ func BenchmarkPodStore(b *testing.B) {
2290
2290
}
2291
2291
}
2292
2292
}
2293
+
2294
+ func TestGetPodStatusReasonValue (t * testing.T ) {
2295
+ reason := "TestReason"
2296
+
2297
+ tests := []struct {
2298
+ name string
2299
+ pod * v1.Pod
2300
+ want float64
2301
+ }{
2302
+ {
2303
+ name : "matches Status.Reason" ,
2304
+ pod : & v1.Pod {
2305
+ Status : v1.PodStatus {
2306
+ Reason : "TestReason" ,
2307
+ },
2308
+ },
2309
+ want : 1 ,
2310
+ },
2311
+ {
2312
+ name : "matches condition Reason" ,
2313
+ pod : & v1.Pod {
2314
+ Status : v1.PodStatus {
2315
+ Conditions : []v1.PodCondition {
2316
+ {
2317
+ Reason : "TestReason" ,
2318
+ },
2319
+ },
2320
+ },
2321
+ },
2322
+ want : 1 ,
2323
+ },
2324
+ {
2325
+ name : "matches container terminated Reason" ,
2326
+ pod : & v1.Pod {
2327
+ Status : v1.PodStatus {
2328
+ ContainerStatuses : []v1.ContainerStatus {
2329
+ {
2330
+ State : v1.ContainerState {
2331
+ Terminated : & v1.ContainerStateTerminated {
2332
+ Reason : "TestReason" ,
2333
+ },
2334
+ },
2335
+ },
2336
+ },
2337
+ },
2338
+ },
2339
+ want : 1 ,
2340
+ },
2341
+ {
2342
+ name : "no match returns 0" ,
2343
+ pod : & v1.Pod {
2344
+ Status : v1.PodStatus {
2345
+ Reason : "OtherReason" ,
2346
+ Conditions : []v1.PodCondition {
2347
+ {
2348
+ Reason : "NotTestReason" ,
2349
+ },
2350
+ },
2351
+ ContainerStatuses : []v1.ContainerStatus {
2352
+ {
2353
+ State : v1.ContainerState {
2354
+ Terminated : & v1.ContainerStateTerminated {
2355
+ Reason : "AnotherReason" ,
2356
+ },
2357
+ },
2358
+ },
2359
+ },
2360
+ },
2361
+ },
2362
+ want : 0 ,
2363
+ },
2364
+ }
2365
+
2366
+ for _ , tt := range tests {
2367
+ t .Run (tt .name , func (t * testing.T ) {
2368
+ got := getPodStatusReasonValue (tt .pod , reason )
2369
+ if got != tt .want {
2370
+ t .Errorf ("getPodStatusReasonValue() = %v, want %v" , got , tt .want )
2371
+ }
2372
+ })
2373
+ }
2374
+ }
You can’t perform that action at this time.
0 commit comments