github.com/hyperledger/aries-framework-go@v0.3.2/pkg/didcomm/common/service/action_test.go (about)

     1  /*
     2  Copyright SecureKey Technologies Inc. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package service
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/stretchr/testify/require"
    13  )
    14  
    15  func TestAction_ActionEvent(t *testing.T) {
    16  	a := Action{}
    17  	require.Nil(t, a.ActionEvent())
    18  }
    19  
    20  func TestAction_RegisterActionEvent(t *testing.T) {
    21  	a := Action{}
    22  	// nil error
    23  	require.EqualError(t, a.RegisterActionEvent(nil), ErrNilChannel.Error())
    24  
    25  	// channel should be the same
    26  	ch := make(chan DIDCommAction)
    27  	require.Nil(t, a.RegisterActionEvent(ch))
    28  	require.EqualValues(t, ch, a.ActionEvent())
    29  
    30  	// register the same channel twice
    31  	newCh := make(chan DIDCommAction)
    32  	require.EqualError(t, a.RegisterActionEvent(newCh), ErrChannelRegistered.Error())
    33  }
    34  
    35  func TestAction_UnregisterActionEvent(t *testing.T) {
    36  	a := Action{}
    37  
    38  	// nil channel
    39  	require.EqualError(t, a.UnregisterActionEvent(nil), ErrNilChannel.Error())
    40  
    41  	// channel was not registered
    42  	ch := make(chan DIDCommAction)
    43  	require.EqualError(t, a.UnregisterActionEvent(ch), ErrInvalidChannel.Error())
    44  
    45  	// happy path
    46  	require.Nil(t, a.RegisterActionEvent(ch))
    47  	require.Nil(t, a.UnregisterActionEvent(ch))
    48  }