github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/core/handlers/library/registry_test.go (about)

     1  /*
     2  Copyright hechain, SecureKey Technologies Inc. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package library
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/hechain20/hechain/core/handlers/auth"
    13  	"github.com/hechain20/hechain/core/handlers/decoration"
    14  	"github.com/stretchr/testify/require"
    15  )
    16  
    17  func TestInitRegistry(t *testing.T) {
    18  	r := InitRegistry(Config{
    19  		AuthFilters: []*HandlerConfig{{Name: "DefaultAuth"}},
    20  		Decorators:  []*HandlerConfig{{Name: "DefaultDecorator"}},
    21  	})
    22  	require.NotNil(t, r)
    23  	authHandlers := r.Lookup(Auth)
    24  	require.NotNil(t, authHandlers)
    25  	filters, isAuthFilters := authHandlers.([]auth.Filter)
    26  	require.True(t, isAuthFilters)
    27  	require.Len(t, filters, 1)
    28  
    29  	decorationHandlers := r.Lookup(Decoration)
    30  	require.NotNil(t, decorationHandlers)
    31  	decorators, isDecorators := decorationHandlers.([]decoration.Decorator)
    32  	require.True(t, isDecorators)
    33  	require.Len(t, decorators, 1)
    34  }
    35  
    36  func TestLoadCompiledInvalid(t *testing.T) {
    37  	defer func() {
    38  		if r := recover(); r == nil {
    39  			t.Errorf("Expected panic with invalid factory method")
    40  		}
    41  	}()
    42  
    43  	testReg := registry{}
    44  	testReg.loadCompiled("InvalidFactory", Auth)
    45  }