github.com/lzy4123/fabric@v2.1.1+incompatible/core/handlers/library/registry_test.go (about) 1 /* 2 Copyright IBM Corp, 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/hyperledger/fabric/core/handlers/auth" 13 "github.com/hyperledger/fabric/core/handlers/decoration" 14 "github.com/stretchr/testify/assert" 15 ) 16 17 func TestInitRegistry(t *testing.T) { 18 r := InitRegistry(Config{ 19 AuthFilters: []*HandlerConfig{{Name: "DefaultAuth"}}, 20 Decorators: []*HandlerConfig{{Name: "DefaultDecorator"}}, 21 }) 22 assert.NotNil(t, r) 23 authHandlers := r.Lookup(Auth) 24 assert.NotNil(t, authHandlers) 25 filters, isAuthFilters := authHandlers.([]auth.Filter) 26 assert.True(t, isAuthFilters) 27 assert.Len(t, filters, 1) 28 29 decorationHandlers := r.Lookup(Decoration) 30 assert.NotNil(t, decorationHandlers) 31 decorators, isDecorators := decorationHandlers.([]decoration.Decorator) 32 assert.True(t, isDecorators) 33 assert.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 }