| 159 | } |
| 160 | |
| 161 | func TestEncoding_Deterministic(t *testing.T) { |
| 162 | t.Parallel() |
| 163 | |
| 164 | m := orderedmap.New[A, I]() |
| 165 | m.Store(A{Number: 1}, &A{}) |
| 166 | m.Store(A{Number: 2}, &B{}) |
| 167 | |
| 168 | // We encode the map 10 times and check that the result is always the same. |
| 169 | var previous []byte |
| 170 | for i := 0; i < 10; i++ { |
| 171 | var buf bytes.Buffer |
| 172 | err := gob.NewEncoder(&buf).Encode(m) |
| 173 | require.NoError(t, err) |
| 174 | require.NotEmpty(t, buf.Bytes()) |
| 175 | if len(previous) == 0 { |
| 176 | previous = buf.Bytes() |
| 177 | continue |
| 178 | } |
| 179 | require.Equal(t, previous, buf.Bytes()) |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | func TestEncode_Empty(t *testing.T) { |
| 184 | t.Parallel() |