mirror of
https://github.com/gravitational/teleport
synced 2024-10-21 17:53:28 +00:00
566b7cc457
`require` is a sister package to `assert` that terminates the test on failure. `assert` records the failure but lets the test proceed, which is un-intuitive. Also update all existing tests to match.
75 lines
1.5 KiB
Go
75 lines
1.5 KiB
Go
package service
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestProcessStateGetState(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
desc string
|
|
states map[string]*componentState
|
|
want componentStateEnum
|
|
}{
|
|
{
|
|
desc: "no components",
|
|
states: map[string]*componentState{},
|
|
want: stateStarting,
|
|
},
|
|
{
|
|
desc: "one component in stateOK",
|
|
states: map[string]*componentState{
|
|
"one": {state: stateOK},
|
|
},
|
|
want: stateOK,
|
|
},
|
|
{
|
|
desc: "multiple components in stateOK",
|
|
states: map[string]*componentState{
|
|
"one": {state: stateOK},
|
|
"two": {state: stateOK},
|
|
"three": {state: stateOK},
|
|
},
|
|
want: stateOK,
|
|
},
|
|
{
|
|
desc: "multiple components, one is degraded",
|
|
states: map[string]*componentState{
|
|
"one": {state: stateRecovering},
|
|
"two": {state: stateDegraded},
|
|
"three": {state: stateOK},
|
|
},
|
|
want: stateDegraded,
|
|
},
|
|
{
|
|
desc: "multiple components, one is recovering",
|
|
states: map[string]*componentState{
|
|
"one": {state: stateOK},
|
|
"two": {state: stateRecovering},
|
|
"three": {state: stateOK},
|
|
},
|
|
want: stateRecovering,
|
|
},
|
|
{
|
|
desc: "multiple components, one is starting",
|
|
states: map[string]*componentState{
|
|
"one": {state: stateOK},
|
|
"two": {state: stateStarting},
|
|
"three": {state: stateOK},
|
|
},
|
|
want: stateStarting,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.desc, func(t *testing.T) {
|
|
ps := &processState{states: tt.states}
|
|
got := ps.getState()
|
|
require.Equal(t, got, tt.want)
|
|
})
|
|
}
|
|
}
|