github.com/koko1123/flow-go-1@v0.29.6/model/flow/cluster_test.go (about) 1 package flow_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 "github.com/stretchr/testify/require" 8 9 "github.com/koko1123/flow-go-1/model/flow" 10 "github.com/koko1123/flow-go-1/model/flow/factory" 11 "github.com/koko1123/flow-go-1/utils/unittest" 12 ) 13 14 // Test that converting between assignments and clusters does not change contents or order. 15 func TestClusterAssignments(t *testing.T) { 16 17 identities := unittest.IdentityListFixture(100, unittest.WithRole(flow.RoleCollection)) 18 assignments := unittest.ClusterAssignment(10, identities) 19 assert.Len(t, assignments, 10) 20 21 clusters, err := factory.NewClusterList(assignments, identities) 22 require.NoError(t, err) 23 assert.Equal(t, assignments, clusters.Assignments()) 24 } 25 26 func TestAssignmentList_EqualTo(t *testing.T) { 27 28 t.Run("empty are equal", func(t *testing.T) { 29 a := flow.AssignmentList{} 30 b := flow.AssignmentList{} 31 32 require.True(t, a.EqualTo(b)) 33 require.True(t, b.EqualTo(a)) 34 }) 35 36 t.Run("different length arent equal", func(t *testing.T) { 37 a := flow.AssignmentList{} 38 b := flow.AssignmentList{[]flow.Identifier{[32]byte{}}} 39 40 require.False(t, a.EqualTo(b)) 41 require.False(t, b.EqualTo(a)) 42 }) 43 44 t.Run("different nested length arent equal", func(t *testing.T) { 45 a := flow.AssignmentList{[]flow.Identifier{[32]byte{}}} 46 b := flow.AssignmentList{[]flow.Identifier{[32]byte{}, [32]byte{}}} 47 48 require.False(t, a.EqualTo(b)) 49 require.False(t, b.EqualTo(a)) 50 }) 51 52 t.Run("equal length with wrong data means not equal", func(t *testing.T) { 53 a := flow.AssignmentList{[]flow.Identifier{[32]byte{1, 2, 3}, [32]byte{2, 2, 2}}} 54 b := flow.AssignmentList{[]flow.Identifier{[32]byte{1, 2, 3}, [32]byte{}}} 55 56 require.False(t, a.EqualTo(b)) 57 require.False(t, b.EqualTo(a)) 58 }) 59 60 t.Run("equal length with same data means equal", func(t *testing.T) { 61 a := flow.AssignmentList{[]flow.Identifier{[32]byte{1, 2, 3}, [32]byte{2, 2, 2}}} 62 b := flow.AssignmentList{[]flow.Identifier{[32]byte{1, 2, 3}, [32]byte{2, 2, 2}}} 63 64 require.True(t, a.EqualTo(b)) 65 require.True(t, b.EqualTo(a)) 66 }) 67 }