github.com/0chain/gosdk@v1.17.11/zboxcore/zboxutil/http_test.go (about) 1 package zboxutil 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestIsCurrentDominantStatus(t *testing.T) { 10 for _, tc := range []struct { 11 name string 12 status int 13 runningTotalPerStatus map[int]int 14 runningMax int 15 wantIsDominant bool 16 }{ 17 { 18 name: "first response - 200", 19 status: 200, 20 runningTotalPerStatus: map[int]int{200: 1}, 21 runningMax: 1, 22 wantIsDominant: true, 23 }, 24 { 25 name: "first response - 500", 26 status: 500, 27 runningTotalPerStatus: map[int]int{500: 1}, 28 runningMax: 1, 29 wantIsDominant: true, 30 }, 31 { 32 name: "current response - 200 (previous was 500) - tiebreakers", 33 status: 200, 34 runningTotalPerStatus: map[int]int{200: 1, 500: 1}, 35 runningMax: 1, 36 wantIsDominant: true, 37 }, 38 { 39 name: "current response - 500 (previous was 200) - tiebreakers - should not be dominant", 40 status: 500, 41 runningTotalPerStatus: map[int]int{200: 1, 500: 1}, 42 runningMax: 1, 43 wantIsDominant: false, 44 }, 45 { 46 name: "current response - 500 (previous were 200, 500)", 47 status: 500, 48 runningTotalPerStatus: map[int]int{200: 1, 500: 2}, 49 runningMax: 2, 50 wantIsDominant: true, 51 }, 52 { 53 name: "current response - 200 (previous were 400, 404, 500) - tiebreakers", 54 status: 200, 55 runningTotalPerStatus: map[int]int{200: 1, 400: 1, 404: 1, 500: 1}, 56 runningMax: 1, 57 wantIsDominant: true, 58 }, 59 } { 60 tt := tc 61 t.Run(tt.name, func(t *testing.T) { 62 got := isCurrentDominantStatus(tt.status, tt.runningTotalPerStatus, tt.runningMax) 63 64 assert.Equal(t, tt.wantIsDominant, got) 65 }) 66 } 67 }