github.com/hyperledger/aries-framework-go@v0.3.2/pkg/internal/didcommutil/util_test.go (about)

     1  /*
     2  Copyright SecureKey Technologies Inc. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package didcommutil_test
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/stretchr/testify/require"
    13  
    14  	"github.com/hyperledger/aries-framework-go/pkg/internal/didcommutil"
    15  )
    16  
    17  const testServiceType = "ServiceType"
    18  
    19  func TestGetServiceType(t *testing.T) {
    20  	t.Run("success - string", func(t *testing.T) {
    21  		serviceType := didcommutil.GetServiceType(testServiceType)
    22  		require.Equal(t, testServiceType, serviceType)
    23  	})
    24  
    25  	t.Run("success - an array of strings", func(t *testing.T) {
    26  		serviceType := didcommutil.GetServiceType([]string{testServiceType, "OtherServiceType"})
    27  		require.Equal(t, testServiceType, serviceType)
    28  	})
    29  
    30  	t.Run("success - an array of interfaces", func(t *testing.T) {
    31  		serviceType := didcommutil.GetServiceType([]interface{}{testServiceType, "OtherServiceType"})
    32  		require.Equal(t, testServiceType, serviceType)
    33  	})
    34  
    35  	t.Run("success - wrong type (return empty)", func(t *testing.T) {
    36  		serviceType := didcommutil.GetServiceType(123)
    37  		require.Equal(t, "", serviceType)
    38  	})
    39  
    40  	t.Run("success - wrong interface in an array", func(t *testing.T) {
    41  		serviceType := didcommutil.GetServiceType([]interface{}{123, testServiceType})
    42  		require.Equal(t, "", serviceType)
    43  	})
    44  }