github.com/inklabsfoundation/inkchain@v0.17.1-0.20181025012015-c3cef8062f19/common/config/consortiums_test.go (about)

     1  /*
     2  Copyright IBM Corp. 2017 All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8                   http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  package config
    17  
    18  import (
    19  	"testing"
    20  
    21  	"github.com/stretchr/testify/assert"
    22  )
    23  
    24  func TestConsortiums(t *testing.T) {
    25  
    26  	csg := NewConsortiumsGroup(nil)
    27  	cg, err := csg.NewGroup("testCG")
    28  	assert.NoError(t, err, "NewGroup shuld not have returned error")
    29  	_, ok := cg.(*ConsortiumGroup)
    30  	assert.Equal(t, true, ok, "NewGroup should have returned a ConsortiumGroup")
    31  
    32  	csc := csg.Allocate()
    33  	_, ok = csc.(*ConsortiumsConfig)
    34  	assert.Equal(t, true, ok, "Allocate should have returned a ConsortiumsConfig")
    35  
    36  	csc.Commit()
    37  	assert.Equal(t, csc, csg.ConsortiumsConfig, "Failed to commit ConsortiumsConfig")
    38  
    39  	err = csc.Validate(t, map[string]ValueProposer{
    40  		"badGroup": &OrganizationGroup{},
    41  	})
    42  	assert.Error(t, err, "Validate should have returned error for wrong type of ValueProposer")
    43  	err = csc.Validate(t, map[string]ValueProposer{
    44  		"testGroup": cg,
    45  	})
    46  	assert.NoError(t, err, "Validate should not have returned error")
    47  	assert.Equal(t, cg, csc.(*ConsortiumsConfig).Consortiums()["testGroup"],
    48  		"Expected consortium groups to be the same")
    49  
    50  }