|
1 | 1 | /*
|
2 |
| -Copyright IBM Corp. 2016 All Rights Reserved. |
| 2 | +Copyright IBM Corp. All Rights Reserved. |
3 | 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. |
| 4 | +SPDX-License-Identifier: Apache-2.0 |
15 | 5 | */
|
16 | 6 |
|
17 | 7 | package cauthdsl
|
@@ -179,3 +169,42 @@ func TestNilSignaturePolicyEnvelope(t *testing.T) {
|
179 | 169 | _, err := compile(nil, nil, &mockDeserializer{})
|
180 | 170 | assert.Error(t, err, "Fail to compile")
|
181 | 171 | }
|
| 172 | + |
| 173 | +func TestDeduplicate(t *testing.T) { |
| 174 | + ids := []*cb.SignedData{ |
| 175 | + &cb.SignedData{ |
| 176 | + Identity: []byte("id1"), |
| 177 | + }, |
| 178 | + &cb.SignedData{ |
| 179 | + Identity: []byte("id2"), |
| 180 | + }, |
| 181 | + &cb.SignedData{ |
| 182 | + Identity: []byte("id3"), |
| 183 | + }, |
| 184 | + } |
| 185 | + |
| 186 | + t.Run("Empty", func(t *testing.T) { |
| 187 | + result := deduplicate([]*cb.SignedData{}) |
| 188 | + assert.Equal(t, []*cb.SignedData{}, result, "Should have no identities") |
| 189 | + }) |
| 190 | + |
| 191 | + t.Run("NoDuplication", func(t *testing.T) { |
| 192 | + result := deduplicate(ids) |
| 193 | + assert.Equal(t, ids, result, "No identities should have been removed") |
| 194 | + }) |
| 195 | + |
| 196 | + t.Run("AllDuplication", func(t *testing.T) { |
| 197 | + result := deduplicate([]*cb.SignedData{ids[0], ids[0], ids[0]}) |
| 198 | + assert.Equal(t, []*cb.SignedData{ids[0]}, result, "All but the first identity should have been removed") |
| 199 | + }) |
| 200 | + |
| 201 | + t.Run("DuplicationPreservesOrder", func(t *testing.T) { |
| 202 | + result := deduplicate([]*cb.SignedData{ids[1], ids[0], ids[0]}) |
| 203 | + assert.Equal(t, []*cb.SignedData{ids[1], ids[0]}, result, "The third identity should have been dropped") |
| 204 | + }) |
| 205 | + |
| 206 | + t.Run("ComplexDuplication", func(t *testing.T) { |
| 207 | + result := deduplicate([]*cb.SignedData{ids[1], ids[0], ids[0], ids[1], ids[2], ids[0], ids[2], ids[1]}) |
| 208 | + assert.Equal(t, []*cb.SignedData{ids[1], ids[0], ids[2]}, result, "Expected only three non-duplicate identities") |
| 209 | + }) |
| 210 | +} |
0 commit comments