Files
teleport/lib/service/state_test.go
T
Roman Tkachenko d78f6925a4 Revert readyz changes (#12244)
* Revert "Make `PortList.Pop()` thread-safe (#11799)"

This reverts commit a17337d1a1.

* Revert "Ensure stateOK is reported only when all components have sent updates (#11249)"

This reverts commit b749302e2c.

* Revert "Throw startup error if `TeleportReadyEvent` is not emitted (#11725)"

This reverts commit 933e247287.

* Revert "Fix ProxyKube not reporting its readiness (#12150)"

This reverts commit 6cdcfe7721.
2022-04-26 22:16:55 +00:00

89 lines
2.1 KiB
Go

// Copyright 2021 Gravitational, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
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)
})
}
}