teleport/lib/service/state_test.go
Andrew Lytvynov 566b7cc457 RFD 1: user testify/require instead of testify/assert
`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.
2020-10-16 00:15:25 +00:00

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)
})
}
}