@@ -32,37 +32,45 @@ func verifyItemsResult(t *testing.T, template Template, count int) {
32
32
t .Fatalf ("Should not have errored: %s" , err )
33
33
}
34
34
35
- config , err := UnmarshalConfig (configEnv .Config )
35
+ configNext , err := UnmarshalConfigNext (configEnv .Config )
36
36
if err != nil {
37
37
t .Fatalf ("Should not have errored: %s" , err )
38
38
}
39
+ config := ConfigNextToConfig (configNext )
39
40
40
41
if len (config .Items ) != count {
41
42
t .Errorf ("Expected %d items, but got %d" , count , len (config .Items ))
42
43
}
43
44
44
- for i , item := range config .Items {
45
- expected := fmt .Sprintf ("%d" , i )
46
- assert .Equal (t , expected , string (item .Value ), "Expected %s but got %s" , expected , item .Value )
45
+ for i , _ := range config .Items {
46
+ count := 0
47
+ for _ , item := range config .Items {
48
+ key := fmt .Sprintf ("%d" , i )
49
+ if key == item .Key {
50
+ count ++
51
+ }
52
+ }
53
+ expected := 1
54
+ assert .Equal (t , expected , count , "Expected %d but got %d for %d" , expected , count , i )
47
55
}
48
56
}
49
57
50
58
func TestSimpleTemplate (t * testing.T ) {
51
59
simple := NewSimpleTemplate (
52
- & cb.ConfigItem {Value : [] byte ( "0" ) },
53
- & cb.ConfigItem {Value : [] byte ( "1" ) },
60
+ & cb.ConfigItem {Type : cb . ConfigItem_Orderer , Key : "0" },
61
+ & cb.ConfigItem {Type : cb . ConfigItem_Orderer , Key : "1" },
54
62
)
55
63
verifyItemsResult (t , simple , 2 )
56
64
}
57
65
58
66
func TestCompositeTemplate (t * testing.T ) {
59
67
composite := NewCompositeTemplate (
60
68
NewSimpleTemplate (
61
- & cb.ConfigItem {Value : [] byte ( "0" ) },
62
- & cb.ConfigItem {Value : [] byte ( "1" ) },
69
+ & cb.ConfigItem {Type : cb . ConfigItem_Orderer , Key : "0" },
70
+ & cb.ConfigItem {Type : cb . ConfigItem_Orderer , Key : "1" },
63
71
),
64
72
NewSimpleTemplate (
65
- & cb.ConfigItem {Value : [] byte ( "2" ) },
73
+ & cb.ConfigItem {Type : cb . ConfigItem_Orderer , Key : "2" },
66
74
),
67
75
)
68
76
@@ -71,8 +79,8 @@ func TestCompositeTemplate(t *testing.T) {
71
79
72
80
func TestNewChainTemplate (t * testing.T ) {
73
81
simple := NewSimpleTemplate (
74
- & cb.ConfigItem {Value : [] byte ( "1" ) },
75
- & cb.ConfigItem {Value : [] byte ( "2" ) },
82
+ & cb.ConfigItem {Type : cb . ConfigItem_Orderer , Key : "0" },
83
+ & cb.ConfigItem {Type : cb . ConfigItem_Orderer , Key : "1" },
76
84
)
77
85
78
86
creationPolicy := "Test"
@@ -84,24 +92,40 @@ func TestNewChainTemplate(t *testing.T) {
84
92
t .Fatalf ("Error creation a chain creation config" )
85
93
}
86
94
87
- config , err := UnmarshalConfig (configEnv .Config )
95
+ configNext , err := UnmarshalConfigNext (configEnv .Config )
88
96
if err != nil {
89
97
t .Fatalf ("Should not have errored: %s" , err )
90
98
}
99
+ config := ConfigNextToConfig (configNext )
91
100
92
101
if expected := 3 ; len (config .Items ) != expected {
93
102
t .Fatalf ("Expected %d items, but got %d" , expected , len (config .Items ))
94
103
}
95
104
96
- for i , item := range config .Items {
97
- if i == 0 {
98
- if item .Key != CreationPolicyKey {
99
- t .Errorf ("First item should have been the creation policy" )
100
- }
101
- } else {
102
- if expected := fmt .Sprintf ("%d" , i ); string (item .Value ) != expected {
103
- t .Errorf ("Expected %s but got %s" , expected , item .Value )
105
+ for i , _ := range config .Items {
106
+ if i == len (config .Items )- 1 {
107
+ break
108
+ }
109
+ count := 0
110
+ for _ , item := range config .Items {
111
+ key := fmt .Sprintf ("%d" , i )
112
+ if key == item .Key {
113
+ count ++
104
114
}
105
115
}
116
+ expected := 1
117
+ assert .Equal (t , expected , count , "Expected %d but got %d for %d" , expected , count , i )
118
+ }
119
+
120
+ foundCreationPolicy := false
121
+ for _ , item := range config .Items {
122
+ if item .Key == CreationPolicyKey {
123
+ foundCreationPolicy = true
124
+ continue
125
+ }
126
+ }
127
+
128
+ if ! foundCreationPolicy {
129
+ t .Errorf ("Should have found the creation policy" )
106
130
}
107
131
}
0 commit comments