github.com/iotexproject/iotex-core@v1.14.1-rc1/pkg/lifecycle/ready_test.go (about)

     1  // Copyright (c) 2021 IoTeX Foundation
     2  // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
     3  // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
     4  // This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
     5  
     6  package lifecycle
     7  
     8  import (
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func TestReady(t *testing.T) {
    15  	r := require.New(t)
    16  
    17  	ready := Readiness{}
    18  	r.False(ready.IsReady())
    19  	r.Equal(ErrWrongState, ready.TurnOff())
    20  
    21  	// ready after turn on
    22  	r.NoError(ready.TurnOn())
    23  	r.True(ready.IsReady())
    24  	r.Equal(ErrWrongState, ready.TurnOn()) // cannot turn on again
    25  
    26  	// not ready after turn off
    27  	r.NoError(ready.TurnOff())
    28  	r.False(ready.IsReady())
    29  	r.Equal(ErrWrongState, ready.TurnOff()) // cannot turn off again
    30  }